Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sorting.php
Go to the documentation of this file.
1 <?php
11 
16 class Sorting extends \Magento\Config\Model\Config\Structure\AbstractMapper
17 {
24  public function map(array $data)
25  {
26  foreach ($data['config']['system'] as &$element) {
27  $element = $this->_processConfig($element);
28  }
29  return $data;
30  }
31 
36  protected function _processConfig($data)
37  {
38  foreach ($data as &$item) {
39  if ($this->_hasValue('children', $item)) {
40  $item['children'] = $this->_processConfig($item['children']);
41  }
42  }
43  uasort($data, [$this, '_cmp']);
44  return $data;
45  }
46 
54  protected function _cmp($elementA, $elementB)
55  {
56  $sortIndexA = 0;
57  if ($this->_hasValue('sortOrder', $elementA)) {
58  $sortIndexA = (float)$elementA['sortOrder'];
59  }
60  $sortIndexB = 0;
61  if ($this->_hasValue('sortOrder', $elementB)) {
62  $sortIndexB = (float)$elementB['sortOrder'];
63  }
64 
65  if ($sortIndexA == $sortIndexB) {
66  return 0;
67  }
68 
69  return $sortIndexA < $sortIndexB ? -1 : 1;
70  }
71 }
$element
Definition: element.phtml:12