Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Converter.php
Go to the documentation of this file.
1 <?php
7 
9 {
16  public function convert($source)
17  {
18  $fieldsets = [];
19  $xpath = new \DOMXPath($source);
21  foreach ($xpath->query('/config/scope') as $scope) {
22  $scopeId = $scope->attributes->getNamedItem('id')->nodeValue;
23  $fieldsets[$scopeId] = $this->_convertScope($scope);
24  }
25  return $fieldsets;
26  }
27 
34  protected function _convertScope($scope)
35  {
36  $result = [];
37  foreach ($scope->childNodes as $fieldset) {
38  if (!$fieldset instanceof \DOMElement) {
39  continue;
40  }
41  $fieldsetName = $fieldset->attributes->getNamedItem('id')->nodeValue;
42  $result[$fieldsetName] = $this->_convertFieldset($fieldset);
43  }
44  return $result;
45  }
46 
53  protected function _convertFieldset($fieldset)
54  {
55  $result = [];
56  foreach ($fieldset->childNodes as $field) {
57  if (!$field instanceof \DOMElement) {
58  continue;
59  }
60  $fieldName = $field->attributes->getNamedItem('name')->nodeValue;
61  $result[$fieldName] = $this->_convertField($field);
62  }
63  return $result;
64  }
65 
72  protected function _convertField($field)
73  {
74  $result = [];
75  foreach ($field->childNodes as $aspect) {
76  if (!$aspect instanceof \DOMElement) {
77  continue;
78  }
80  $aspectAttributes = $aspect->attributes;
81  $aspectName = $aspectAttributes->getNamedItem('name')->nodeValue;
82  $targetField = $aspectAttributes->getNamedItem('targetField');
83  $result[$aspectName] = $targetField === null ? '*' : $targetField->nodeValue;
84  }
85  return $result;
86  }
87 }
$source
Definition: source.php:23