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
8 
15 class Structure
16 {
22  private $serializableProperties = [
23  'assets',
24  'removeAssets',
25  'title',
26  'metadata',
27  'elementAttributes',
28  'removeElementAttributes',
29  'bodyClasses',
30  'isBodyClassesDeleted',
31  ];
32 
38  protected $assets = [];
39 
45  protected $removeAssets = [];
46 
50  protected $title;
51 
55  protected $metadata = [];
56 
60  protected $elementAttributes = [];
61 
65  protected $removeElementAttributes = [];
66 
70  protected $bodyClasses = [];
71 
75  protected $isBodyClassesDeleted = false;
76 
83  public function setElementAttribute($element, $attributeName, $attributeValue)
84  {
85  if (empty($attributeValue)) {
86  $this->removeElementAttributes[$element][] = $attributeName;
87  } else {
88  $this->elementAttributes[$element][$attributeName] = (string)$attributeValue;
89  }
90  return $this;
91  }
92 
97  {
98  foreach ($this->removeElementAttributes as $element => $attributes) {
99  foreach ($attributes as $attributeName) {
100  unset($this->elementAttributes[$element][$attributeName]);
101  }
102  if (empty($this->elementAttributes[$element])) {
103  unset($this->elementAttributes[$element]);
104  }
105  }
106  $this->removeElementAttributes = [];
107  return $this;
108  }
109 
114  public function setBodyClass($value)
115  {
116  if (empty($value)) {
117  $this->isBodyClassesDeleted = true;
118  } else {
119  $this->bodyClasses[] = $value;
120  }
121  return $this;
122  }
123 
127  public function getBodyClasses()
128  {
129  return $this->isBodyClassesDeleted ? [] : $this->bodyClasses;
130  }
131 
135  public function getElementAttributes()
136  {
138  }
139 
144  public function setTitle($title)
145  {
146  $this->title = (string)$title;
147  return $this;
148  }
149 
153  public function getTitle()
154  {
155  return $this->title;
156  }
157 
163  public function setMetadata($name, $content)
164  {
165  $this->metadata[$name] = (string)$content;
166  return $this;
167  }
168 
172  public function getMetadata()
173  {
174  return $this->metadata;
175  }
176 
182  public function addAssets($name, $attributes)
183  {
184  $this->assets[$name] = $attributes;
185  return $this;
186  }
187 
192  public function removeAssets($name)
193  {
194  $this->removeAssets[$name] = $name;
195  return $this;
196  }
197 
201  public function processRemoveAssets()
202  {
203  $this->assets = array_diff_key($this->assets, $this->removeAssets);
204  $this->removeAssets = [];
205  return $this;
206  }
207 
211  public function getAssets()
212  {
213  return $this->assets;
214  }
215 
222  public function __toArray()
223  {
224  $result = [];
225  foreach ($this->serializableProperties as $property) {
226  $result[$property] = $this->{$property};
227  }
228 
229  return $result;
230  }
231 
239  public function populateWithArray(array $data)
240  {
241  foreach ($this->serializableProperties as $property) {
242  $this->{$property} = $this->getArrayValueByKey($property, $data);
243  }
244  }
245 
253  private function getArrayValueByKey($key, array $array)
254  {
255  return $array[$key] ?? [];
256  }
257 }
setElementAttribute($element, $attributeName, $attributeValue)
Definition: Structure.php:83
$value
Definition: gender.phtml:16
$attributes
Definition: matrix.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14
$element
Definition: element.phtml:12