Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Structure Class Reference
Inheritance diagram for Structure:
SearchInterface

Public Member Functions

 __construct (\Magento\Config\Model\Config\Structure\Data $structureData, \Magento\Config\Model\Config\Structure\Element\Iterator\Tab $tabIterator, \Magento\Config\Model\Config\Structure\Element\FlyweightFactory $flyweightFactory, ScopeDefiner $scopeDefiner)
 
 getTabs ()
 
 getSectionList ()
 
 getElement ($path)
 
 getElementByConfigPath ($path)
 
 getElementByPathParts (array $pathParts)
 
 getFieldPathsByAttribute ($attributeName, $attributeValue)
 
 getFieldPaths ()
 

Data Fields

const TYPE_KEY = '_elementType'
 

Protected Member Functions

 _createEmptyElement (array $pathParts)
 
 _getGroupFieldPathsByAttribute (array $fields, $parentPath, $attributeName, $attributeValue)
 

Protected Attributes

 $_data
 
 $_tabIterator
 
 $_flyweightFactory
 
 $_scopeDefiner
 
 $_elements
 
 $sectionList
 

Detailed Description

System configuration structure.

All paths are declared in module's system.xml.

<section id="section_id">
<group id="group_id" ...>
<field id="field_one_id" ...>
<label>Field One</label>
...
</field>
<field id="field_two_id" ...>
<label>Field Two</label>
<config_path>section/group/field</config_path>
...
</field>
</group>
</section>

Structure path is the nested path of node ids (section, group, field).

Config path is the path which is declared in <config_path> node. If this node is not provided then config path is the same as structure path.

With the example above you can see that the field <field id="field_one_id"> has the next paths:

Also you can see that the field <field id="field_two_id"> has the next paths:

@api

Since
100.0.2

Definition at line 47 of file Structure.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Config\Model\Config\Structure\Data$structureData
\Magento\Config\Model\Config\Structure\Element\Iterator\Tab$tabIterator
\Magento\Config\Model\Config\Structure\Element\FlyweightFactory$flyweightFactory
ScopeDefiner$scopeDefiner

Definition at line 121 of file Structure.php.

126  {
127  $this->_data = $structureData->get();
128  $this->_tabIterator = $tabIterator;
129  $this->_flyweightFactory = $flyweightFactory;
130  $this->_scopeDefiner = $scopeDefiner;
131  }

Member Function Documentation

◆ _createEmptyElement()

_createEmptyElement ( array  $pathParts)
protected

Create empty element data

Parameters
string[]$pathParts
Returns
array

Definition at line 258 of file Structure.php.

259  {
260  switch (count($pathParts)) {
261  case 1:
262  $elementType = 'section';
263  break;
264  case 2:
265  $elementType = 'group';
266  break;
267  default:
268  $elementType = 'field';
269  }
270  $elementId = array_pop($pathParts);
271  return ['id' => $elementId, 'path' => implode('/', $pathParts), '_elementType' => $elementType];
272  }

◆ _getGroupFieldPathsByAttribute()

_getGroupFieldPathsByAttribute ( array  $fields,
  $parentPath,
  $attributeName,
  $attributeValue 
)
protected

Find group fields with specified attribute and attribute value

Parameters
array$fields
string$parentPath
string$attributeName
mixed$attributeValue
Returns
array

Definition at line 319 of file Structure.php.

320  {
321  $result = [];
322  foreach ($fields as $field) {
323  if (isset($field['children'])) {
325  $field['children'],
326  $parentPath . '/' . $field['id'],
327  $attributeName,
328  $attributeValue
329  );
330  } elseif (isset($field[$attributeName]) && $field[$attributeName] == $attributeValue) {
331  $result[] = $parentPath . '/' . $field['id'];
332  }
333  }
334  return $result;
335  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$fields
Definition: details.phtml:14
_getGroupFieldPathsByAttribute(array $fields, $parentPath, $attributeName, $attributeValue)
Definition: Structure.php:319

◆ getElement()

getElement (   $path)

Find element by structure path

Parameters
string$pathThe structure path
Returns
\Magento\Config\Model\Config\Structure\ElementInterface|null

Implements SearchInterface.

Definition at line 178 of file Structure.php.

179  {
180  return $this->getElementByPathParts(explode('/', $path));
181  }
getElementByPathParts(array $pathParts)
Definition: Structure.php:227

◆ getElementByConfigPath()

getElementByConfigPath (   $path)

Find element by config path

Parameters
string$pathThe configuration path
Returns
\Magento\Config\Model\Config\Structure\ElementInterface|null
Since
101.0.0

Definition at line 190 of file Structure.php.

191  {
192  $allPaths = $this->getFieldPaths();
193 
194  if (isset($allPaths[$path])) {
195  $path = array_shift($allPaths[$path]);
196  }
197 
198  return $this->getElementByPathParts(explode('/', $path));
199  }
getElementByPathParts(array $pathParts)
Definition: Structure.php:227

◆ getElementByPathParts()

getElementByPathParts ( array  $pathParts)

Find element by path parts

Parameters
string[]$pathParts
Returns
\Magento\Config\Model\Config\Structure\ElementInterface|null

Definition at line 227 of file Structure.php.

228  {
229  $path = implode('_', $pathParts);
230  if (isset($this->_elements[$path])) {
231  return $this->_elements[$path];
232  }
233  $children = [];
234  if ($this->_data) {
235  $children = $this->_data['sections'];
236  }
237  $child = [];
238  foreach ($pathParts as $pathPart) {
239  if ($children && (array_key_exists($pathPart, $children))) {
240  $child = $children[$pathPart];
241  $children = array_key_exists('children', $child) ? $child['children'] : [];
242  } else {
243  $child = $this->_createEmptyElement($pathParts);
244  break;
245  }
246  }
247  $this->_elements[$path] = $this->_flyweightFactory->create($child['_elementType']);
248  $this->_elements[$path]->setData($child, $this->_scopeDefiner->getScope());
249  return $this->_elements[$path];
250  }
$children
Definition: actions.phtml:11

◆ getFieldPaths()

getFieldPaths ( )

Collects config paths and their structure paths from configuration files. Returns the map of config paths and their structure paths.

All paths are declared in module's system.xml.

<section id="section_id">
<group id="group_id" ...>
<field id="field_one_id" ...>
<label>Field One</label>
...
</field>
<field id="field_two_id" ...>
<label>Field Two</label>
<config_path>section/group/field</config_path>
...
</field>
</group>
</section>

If <config_path> node does not exist, then config path duplicates structure path. The result of this example will be:

[
'section_id/group_id/field_one_id' => [
'section_id/group_id/field_one_id'
],
'section/group/field' => [
'section_id/group_id/field_two_id'
]
Returns
array An array of config path to config structure path map
Since
101.0.0

Definition at line 374 of file Structure.php.

375  {
376  $sections = !empty($this->_data['sections']) ? $this->_data['sections'] : [];
377 
378  if (!$this->mappedPaths) {
379  $this->mappedPaths = $this->getFieldsRecursively($sections);
380  }
381 
382  return $this->mappedPaths;
383  }

◆ getFieldPathsByAttribute()

getFieldPathsByAttribute (   $attributeName,
  $attributeValue 
)

Retrieve paths of fields that have provided attributes with provided values

Parameters
string$attributeName
mixed$attributeValue
Returns
array

Definition at line 281 of file Structure.php.

282  {
283  $result = [];
284  if (empty($this->_data['sections'])) {
285  return $result;
286  }
287 
288  foreach ($this->_data['sections'] as $section) {
289  if (!isset($section['children'])) {
290  continue;
291  }
292  foreach ($section['children'] as $group) {
293  if (isset($group['children'])) {
294  $path = $section['id'] . '/' . $group['id'];
295  $result = array_merge(
296  $result,
298  $group['children'],
299  $path,
300  $attributeName,
301  $attributeValue
302  )
303  );
304  }
305  }
306  }
307  return $result;
308  }
$group
Definition: sections.phtml:16
_getGroupFieldPathsByAttribute(array $fields, $parentPath, $attributeName, $attributeValue)
Definition: Structure.php:319

◆ getSectionList()

getSectionList ( )

Retrieve config section list

Returns
array @SuppressWarnings(PHPMD.UnusedLocalVariable)
Since
100.1.0

Definition at line 158 of file Structure.php.

159  {
160  if (empty($this->sectionList)) {
161  foreach ($this->_data['sections'] as $sectionId => $section) {
162  if (array_key_exists('children', $section) && is_array($section['children'])) {
163  foreach ($section['children'] as $childId => $child) {
164  $this->sectionList[$sectionId . '_' . $childId] = true;
165  }
166  }
167  }
168  }
169  return $this->sectionList;
170  }

◆ getTabs()

getTabs ( )

Retrieve tab iterator

Returns
\Magento\Config\Model\Config\Structure\Element\Iterator

Definition at line 138 of file Structure.php.

139  {
140  if (isset($this->_data['sections'])) {
141  foreach ($this->_data['sections'] as $sectionId => $section) {
142  if (isset($section['tab']) && $section['tab']) {
143  $this->_data['tabs'][$section['tab']]['children'][$sectionId] = $section;
144  }
145  }
146  $this->_tabIterator->setElements($this->_data['tabs'], $this->_scopeDefiner->getScope());
147  }
148  return $this->_tabIterator;
149  }

Field Documentation

◆ $_data

$_data
protected

Definition at line 59 of file Structure.php.

◆ $_elements

$_elements
protected

Definition at line 87 of file Structure.php.

◆ $_flyweightFactory

$_flyweightFactory
protected

Definition at line 73 of file Structure.php.

◆ $_scopeDefiner

$_scopeDefiner
protected

Definition at line 80 of file Structure.php.

◆ $_tabIterator

$_tabIterator
protected

Definition at line 66 of file Structure.php.

◆ $sectionList

$sectionList
protected

Definition at line 95 of file Structure.php.

◆ TYPE_KEY

const TYPE_KEY = '_elementType'

Key that contains field type in structure array

Definition at line 52 of file Structure.php.


The documentation for this class was generated from the following file: