Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Structure.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\Data\Structure as DataStructure;
10 
17 class Structure extends DataStructure
18 {
24  protected $_nameIncrement = [];
25 
29  protected $logger;
30 
34  protected $state;
35 
43  public function __construct(
44  \Psr\Log\LoggerInterface $logger,
45  State $state,
46  array $elements = null
47  ) {
48  $this->logger = $logger;
49  $this->state = $state;
50  parent::__construct($elements);
51  }
52 
64  {
65  if (empty($name)) {
67  }
68  $this->createElement($name, ['type' => $type]);
69  return $name;
70  }
71 
78  protected function _generateAnonymousName($class)
79  {
80  $position = strpos($class, '\\Block\\');
81  $key = $position !== false ? substr($class, $position + 7) : $class;
82  $key = strtolower(trim($key, '_'));
83 
84  if (!isset($this->_nameIncrement[$key])) {
85  $this->_nameIncrement[$key] = 0;
86  }
87 
88  do {
89  $name = $key . '_' . $this->_nameIncrement[$key]++;
90  } while ($this->hasElement($name));
91 
92  return $name;
93  }
94 
108  public function reorderChildElement($parentName, $childName, $offsetOrSibling, $after = true)
109  {
110  if (is_numeric($offsetOrSibling)) {
111  $offset = (int)abs($offsetOrSibling) * ($after ? 1 : -1);
112  $this->reorderChild($parentName, $childName, $offset);
113  } elseif (null === $offsetOrSibling) {
114  $this->reorderChild($parentName, $childName, null);
115  } else {
116  $children = array_keys($this->getChildren($parentName));
117  if ($this->getChildId($parentName, $offsetOrSibling) !== false) {
118  $offsetOrSibling = $this->getChildId($parentName, $offsetOrSibling);
119  }
120  $sibling = $this->_filterSearchMinus($offsetOrSibling, $children, $after);
121  if ($childName !== $sibling) {
122  $siblingParentName = $this->getParentId($sibling);
123  if ($parentName !== $siblingParentName) {
124  if ($this->state->getMode() === State::MODE_DEVELOPER) {
125  $this->logger->info(
126  "Broken reference: the '{$childName}' tries to reorder itself towards '{$sibling}', but " .
127  "their parents are different: '{$parentName}' and '{$siblingParentName}' respectively."
128  );
129  }
130  return;
131  }
132  $this->reorderToSibling($parentName, $childName, $sibling, $after ? 1 : -1);
133  }
134  }
135  }
136 
147  protected function _filterSearchMinus($needle, array $haystack, $isLast)
148  {
149  if ('-' === $needle) {
150  if ($isLast) {
151  return array_pop($haystack);
152  }
153  return array_shift($haystack);
154  }
155  return $needle;
156  }
157 }
createStructuralElement($name, $type, $class)
Definition: Structure.php:63
_filterSearchMinus($needle, array $haystack, $isLast)
Definition: Structure.php:147
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
reorderChild($parentName, $childName, $offsetOrSibling, $after=true)
Definition: Layout.php:410
$children
Definition: actions.phtml:11
__construct(\Psr\Log\LoggerInterface $logger, State $state, array $elements=null)
Definition: Structure.php:43
reorderChildElement($parentName, $childName, $offsetOrSibling, $after=true)
Definition: Structure.php:108
if(!isset($_GET['name'])) $name
Definition: log.php:14