Skip to content

Commit 99c7694

Browse files
committed
MAGETWO-52958: Better Semantic for UI Components
1 parent 568c536 commit 99c7694

File tree

3 files changed

+63
-39
lines changed

3 files changed

+63
-39
lines changed

app/code/Magento/Ui/Config/Converter.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,7 @@ private function toArray(\DOMNode $node)
128128
$result[$attributes[static::NAME_ATTRIBUTE_KEY]] = $this->argumentParser->parse($node);
129129
} else {
130130
$resultComponent = $this->convertNode($node);
131-
$arguments = [];
132-
$childResult = [];
133-
for ($i = 0, $iLength = $node->childNodes->length; $i < $iLength; ++$i) {
134-
$itemNode = $node->childNodes->item($i);
135-
if ($itemNode->localName == null) {
136-
continue;
137-
}
138-
if ($itemNode->localName === static::ARGUMENT_KEY) {
139-
$arguments += $this->toArray($itemNode);
140-
} elseif (
141-
$this->converterUtils->isUiComponent($itemNode)
142-
&& isset($this->schemaMap[$itemNode->localName])
143-
) {
144-
$itemNodeName = $this->converterUtils->getComponentName($itemNode);
145-
$childResult[$itemNodeName] = $this->toArray($itemNode);
146-
// 'uiComponentType' is needed this for Reader to merge default values from definition
147-
$childResult[$itemNodeName]['uiComponentType'] = $itemNode->localName;
148-
} else {
149-
continue;
150-
}
151-
}
131+
list($arguments, $childResult) = $this->convertChildNodes($node);
152132

153133
$result = array_merge(
154134
$this->processArguments($arguments, $resultComponent),
@@ -259,4 +239,37 @@ private function processChildResult(\DOMNode $node, array $childResult)
259239

260240
return $result;
261241
}
242+
243+
/**
244+
* Convert child nodes of $node
245+
*
246+
* @param \DOMNode $node
247+
* @return array
248+
*/
249+
private function convertChildNodes(\DOMNode $node)
250+
{
251+
$arguments = [];
252+
$childResult = [];
253+
for ($i = 0, $iLength = $node->childNodes->length; $i < $iLength; ++$i) {
254+
$itemNode = $node->childNodes->item($i);
255+
if ($itemNode->localName == null) {
256+
continue;
257+
}
258+
if ($itemNode->localName === static::ARGUMENT_KEY) {
259+
$arguments += $this->toArray($itemNode);
260+
} elseif (
261+
$this->converterUtils->isUiComponent($itemNode)
262+
&& isset($this->schemaMap[$itemNode->localName])
263+
) {
264+
$itemNodeName = $this->converterUtils->getComponentName($itemNode);
265+
$childResult[$itemNodeName] = $this->toArray($itemNode);
266+
// 'uiComponentType' is needed this for Reader to merge default values from definition
267+
$childResult[$itemNodeName]['uiComponentType'] = $itemNode->localName;
268+
} else {
269+
continue;
270+
}
271+
}
272+
273+
return array($arguments, $childResult);
274+
}
262275
}

app/code/Magento/Ui/Config/Reader/DefinitionMap/Converter.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,10 @@ private function toArray(\DOMNode $node)
8585
$result[ $attributes[static::NAME_ATTRIBUTE_KEY] ] = $this->argumentParser->parse($node);
8686

8787
} else {
88-
$arguments = [];
89-
$childResult = [];
90-
foreach ($node->childNodes as $itemNode) {
91-
if (empty($itemNode->localName)) {
92-
continue;
93-
}
94-
if ($itemNode->localName === static::ARGUMENT_KEY) {
95-
$arguments += $this->toArray($itemNode);
96-
} else {
97-
$childResult[$this->getComponentName($itemNode)] = $this->toArray($itemNode);
98-
}
99-
}
88+
list($arguments, $childResult) = $this->convertChildNodes($node);
10089

10190
if (!empty($arguments)) {
102-
foreach ($arguments as $name => $argument) {
103-
$result[static::ARGUMENT_KEY][$name] = $argument;
104-
}
91+
$result[static::ARGUMENT_KEY] = $arguments;
10592
}
10693

10794
$result += $childResult;
@@ -181,4 +168,28 @@ private function processMap($componentData, $sourceMap)
181168

182169
return $result;
183170
}
171+
172+
/**
173+
* Convert child nodes of $node
174+
*
175+
* @param \DOMNode $node
176+
* @return array
177+
*/
178+
private function convertChildNodes(\DOMNode $node)
179+
{
180+
$arguments = [];
181+
$childResult = [];
182+
foreach ($node->childNodes as $itemNode) {
183+
if (empty($itemNode->localName)) {
184+
continue;
185+
}
186+
if ($itemNode->localName === static::ARGUMENT_KEY) {
187+
$arguments += $this->toArray($itemNode);
188+
} else {
189+
$childResult[$this->getComponentName($itemNode)] = $this->toArray($itemNode);
190+
}
191+
}
192+
193+
return array($arguments, $childResult);
194+
}
184195
}

app/code/Magento/Ui/Config/Reader/Dom.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ private function nestedMerge(\DOMNode $contextNode, \DOMNodeList $insertedNodes)
117117
/**
118118
* Merge node to matched root elements
119119
*
120-
* @param $rootMatchList
121-
* @param $insertedItem
120+
* @param \DOMNodeList $rootMatchList
121+
* @param \DOMElement $insertedItem
122122
* @return void
123123
*/
124-
private function processMatchedNodes($rootMatchList, $insertedItem)
124+
private function processMatchedNodes(\DOMNodeList $rootMatchList, \DOMElement $insertedItem)
125125
{
126126
foreach ($rootMatchList as $rootItem) {
127127
if ($this->_isTextNode($insertedItem) && $this->_isTextNode($rootItem)) {

0 commit comments

Comments
 (0)