Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Move.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class Move implements Layout\ReaderInterface
11 {
15  const TYPE_MOVE = 'move';
23  public function getSupportedNodes()
24  {
25  return [self::TYPE_MOVE];
26  }
27 
35  public function interpret(Context $readerContext, Layout\Element $currentElement)
36  {
37  $this->scheduleMove($readerContext->getScheduledStructure(), $currentElement);
38  return $this;
39  }
40 
49  protected function scheduleMove(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
50  {
51  $elementName = (string)$currentElement->getAttribute('element');
52  $destination = (string)$currentElement->getAttribute('destination');
53  $alias = (string)$currentElement->getAttribute('as') ?: '';
54  if ($elementName && $destination) {
55  list($siblingName, $isAfter) = $this->beforeAfterToSibling($currentElement);
56  $scheduledStructure->setElementToMove(
58  [$destination, $siblingName, $isAfter, $alias]
59  );
60  } else {
61  throw new \Magento\Framework\Exception\LocalizedException(
62  new \Magento\Framework\Phrase('Element name and destination must be specified.')
63  );
64  }
65  return $this;
66  }
67 
74  protected function beforeAfterToSibling($node)
75  {
76  $result = [null, true];
77  if (isset($node['after'])) {
78  $result[0] = (string)$node['after'];
79  } elseif (isset($node['before'])) {
80  $result[0] = (string)$node['before'];
81  $result[1] = false;
82  }
83  return $result;
84  }
85 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
interpret(Context $readerContext, Layout\Element $currentElement)
Definition: Move.php:35
scheduleMove(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
Definition: Move.php:49
if(!trim($html)) $alias
Definition: details.phtml:20
$elementName
Definition: gallery.phtml:10