Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Element.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  const TYPE_RENDERER = 'renderer';
20 
21  const TYPE_TEMPLATE = 'template';
22 
23  const TYPE_DATA = 'data';
24 
25  const TYPE_BLOCK = 'block';
26 
27  const TYPE_CONTAINER = 'container';
28 
29  const TYPE_ACTION = 'action';
30 
31  const TYPE_ARGUMENTS = 'arguments';
32 
33  const TYPE_ARGUMENT = 'argument';
34 
35  const TYPE_REFERENCE_BLOCK = 'referenceBlock';
36 
37  const TYPE_REFERENCE_CONTAINER = 'referenceContainer';
38 
39  const TYPE_REMOVE = 'remove';
40 
41  const TYPE_MOVE = 'move';
42 
43  const TYPE_UI_COMPONENT = 'uiComponent';
44 
45  const TYPE_HEAD = 'head';
46 
52  const CONTAINER_OPT_HTML_TAG = 'htmlTag';
53 
54  const CONTAINER_OPT_HTML_CLASS = 'htmlClass';
55 
56  const CONTAINER_OPT_HTML_ID = 'htmlId';
57 
58  const CONTAINER_OPT_LABEL = 'label';
59 
69  public function prepare()
70  {
71  switch ($this->getName()) {
72  case self::TYPE_BLOCK:
75  case self::TYPE_DATA:
77  $this->prepareBlock();
78  break;
81  $this->prepareReference();
82  break;
83  case self::TYPE_ACTION:
84  $this->prepareAction();
85  break;
87  $this->prepareActionArgument();
88  break;
89  default:
90  break;
91  }
92  foreach ($this as $child) {
94  $child->prepare();
95  }
96  return $this;
97  }
98 
104  public function getBlockName()
105  {
106  $tagName = (string)$this->getName();
107  $isThisBlock = empty($this['name']) || !in_array(
108  $tagName,
109  [self::TYPE_BLOCK, self::TYPE_REFERENCE_BLOCK]
110  );
111 
112  if ($isThisBlock) {
113  return false;
114  }
115  return (string)$this['name'];
116  }
117 
125  public function getElementName()
126  {
127  $tagName = $this->getName();
128  $isThisContainer = !in_array(
129  $tagName,
130  [self::TYPE_BLOCK, self::TYPE_REFERENCE_BLOCK, self::TYPE_CONTAINER, self::TYPE_REFERENCE_CONTAINER]
131  );
132 
133  if ($isThisContainer) {
134  return false;
135  }
136  return $this->getAttribute('name');
137  }
138 
144  public function getSibling()
145  {
146  $sibling = null;
147  if ($this->getAttribute('before')) {
148  $sibling = $this->getAttribute('before');
149  } elseif ($this->getAttribute('after')) {
150  $sibling = $this->getAttribute('after');
151  }
152 
153  return $sibling;
154  }
155 
161  public function prepareBlock()
162  {
163  $parent = $this->getParent();
164  if (isset($parent['name']) && !isset($this['parent'])) {
165  $this->addAttribute('parent', (string)$parent['name']);
166  }
167 
168  return $this;
169  }
170 
176  public function prepareReference()
177  {
178  return $this;
179  }
180 
186  public function prepareAction()
187  {
188  $parent = $this->getParent();
189  $this->addAttribute('block', (string)$parent['name']);
190 
191  return $this;
192  }
193 
199  public function prepareActionArgument()
200  {
201  return $this;
202  }
203 
209  public function isCacheable()
210  {
211  return !(bool)count($this->xpath('//' . self::TYPE_BLOCK . '[@cacheable="false"]'));
212  }
213 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17