Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Fieldset.php
Go to the documentation of this file.
1 <?php
7 
10 
19 {
26  public function __construct(
27  Factory $factoryElement,
28  CollectionFactory $factoryCollection,
29  Escaper $escaper,
30  $data = []
31  ) {
32  parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
33  $this->_renderer = Form::getFieldsetRenderer();
34  $this->setType('fieldset');
35  if (isset($data['advancedSection'])) {
36  $this->setAdvancedLabel($data['advancedSection']);
37  }
38  }
39 
45  public function getElementHtml()
46  {
47  $html = '<fieldset id="' . $this->getHtmlId() . '"' . $this->serialize(
48  ['class']
49  ) . $this->_getUiId() . '>' . "\n";
50  if ($this->getLegend()) {
51  $html .= '<legend ' . $this->_getUiId('legend') . '>' . $this->getLegend() . '</legend>' . "\n";
52  }
53  $html .= $this->getChildrenHtml();
54  $html .= '</fieldset>' . "\n";
55  $html .= $this->getAfterElementHtml();
56  return $html;
57  }
58 
64  public function getChildren()
65  {
66  $elements = [];
67  foreach ($this->getElements() as $element) {
68  if ($element->getType() != 'fieldset') {
69  $elements[] = $element;
70  }
71  }
72  return $elements;
73  }
74 
80  public function getChildrenHtml()
81  {
82  return $this->_elementsToHtml($this->getChildren());
83  }
84 
90  public function getBasicChildren()
91  {
92  $elements = [];
93  foreach ($this->getElements() as $element) {
94  if (!$element->isAdvanced()) {
95  $elements[] = $element;
96  }
97  }
98  return $elements;
99  }
100 
106  public function getBasicChildrenHtml()
107  {
108  return $this->_elementsToHtml($this->getBasicChildren());
109  }
110 
116  public function getCountBasicChildren()
117  {
118  return count($this->getBasicChildren());
119  }
120 
126  public function getAdvancedChildren()
127  {
128  $elements = [];
129  foreach ($this->getElements() as $element) {
130  if ($element->isAdvanced()) {
131  $elements[] = $element;
132  }
133  }
134  return $elements;
135  }
136 
142  public function getAdvancedChildrenHtml()
143  {
144  return $this->_elementsToHtml($this->getAdvancedChildren());
145  }
146 
152  public function hasAdvanced()
153  {
154  foreach ($this->getElements() as $element) {
155  if ($element->isAdvanced()) {
156  return true;
157  }
158  }
159  return false;
160  }
161 
167  public function getSubFieldset()
168  {
169  $elements = [];
170  foreach ($this->getElements() as $element) {
171  if ($element->getType() == 'fieldset' && !$element->isAdvanced()) {
172  $elements[] = $element;
173  }
174  }
175  return $elements;
176  }
177 
183  public function getSubFieldsetHtml()
184  {
185  return $this->_elementsToHtml($this->getSubFieldset());
186  }
187 
193  public function getDefaultHtml()
194  {
195  $html = '<div><h4 class="icon-head head-edit-form fieldset-legend">' . $this->getLegend() . '</h4>' . "\n";
196  $html .= $this->getElementHtml();
197  $html .= '</div>';
198  return $html;
199  }
200 
211  public function addField($elementId, $type, $config, $after = false, $isAdvanced = false)
212  {
213  $element = parent::addField($elementId, $type, $config, $after);
214  if ($renderer = Form::getFieldsetElementRenderer()) {
215  $element->setRenderer($renderer);
216  }
217  $element->setAdvanced($isAdvanced);
218  return $element;
219  }
220 
227  protected function _elementsToHtml($elements)
228  {
229  $html = '';
230  foreach ($elements as $element) {
231  $html .= $element->toHtml();
232  }
233  return $html;
234  }
235 }
$config
Definition: fraud_order.php:17
$type
Definition: item.phtml:13
static getFieldsetRenderer()
Definition: Form.php:112
__construct(Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, $data=[])
Definition: Fieldset.php:26
static getFieldsetElementRenderer()
Definition: Form.php:120
serialize($attributes=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
addField($elementId, $type, $config, $after=false, $isAdvanced=false)
Definition: Fieldset.php:211
$element
Definition: element.phtml:12