/
repeatable.php
72 lines (64 loc) · 2.73 KB
/
repeatable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
extract($displayData);
/**
* Layout variables
* -----------------
* @var JForm $tmpl The Empty form for template
* @var array $forms Array of JForm instances for render the rows
* @var bool $multiple The multiple state for the form field
* @var int $min Count of minimum repeating in multiple mode
* @var int $max Count of maximum repeating in multiple mode
* @var string $name Name of the input field.
* @var string $fieldname The field name
* @var string $fieldId The field ID
* @var string $control The forms control
* @var string $label The field label
* @var string $description The field description
* @var string $class Classes for the container
* @var array $buttons Array of the buttons that will be rendered
* @var bool $groupByFieldset Whether group the subform fields by it`s fieldset
*/
// Add script
if ($multiple)
{
Factory::getDocument()->getWebAssetManager()
->useScript('webcomponent.field-subform');
}
$class = $class ? ' ' . $class : '';
$sublayout = empty($groupByFieldset) ? 'section' : 'section-byfieldsets';
?>
<div class="subform-repeatable-wrapper subform-layout">
<joomla-field-subform class="subform-repeatable<?php echo $class; ?>" name="<?php echo $name; ?>"
button-add=".group-add" button-remove=".group-remove" button-move="<?php echo empty($buttons['move']) ? '' : '.group-move' ?>"
repeatable-element=".subform-repeatable-group" minimum="<?php echo $min; ?>" maximum="<?php echo $max; ?>">
<?php if (!empty($buttons['add'])) : ?>
<div class="btn-toolbar">
<div class="btn-group">
<button type="button" class="group-add btn btn-sm button btn-success" aria-label="<?php echo Text::_('JGLOBAL_FIELD_ADD'); ?>">
<span class="icon-plus icon-white" aria-hidden="true"></span>
</button>
</div>
</div>
<?php endif; ?>
<?php
foreach ($forms as $k => $form) :
echo $this->sublayout($sublayout, array('form' => $form, 'basegroup' => $fieldname, 'group' => $fieldname . $k, 'buttons' => $buttons));
endforeach;
?>
<?php if ($multiple) : ?>
<template class="subform-repeatable-template-section hidden"><?php
echo trim($this->sublayout($sublayout, array('form' => $tmpl, 'basegroup' => $fieldname, 'group' => $fieldname . 'X', 'buttons' => $buttons)));
?></template>
<?php endif; ?>
</joomla-field-subform>
</div>