TYPO3 CMS  TYPO3_7-6
AbstractJsonElement.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
27  public $xtype = '';
28 
34  public $configuration = [];
35 
41  protected $allowedAttributes = [];
42 
50  protected $childElementsAllowed = true;
51 
58  public function setParameters(array $parameters)
59  {
60  foreach ($this->configuration as $key => $value) {
61  switch ($key) {
62  case 'attributes':
63  $this->setAttributes($parameters);
64  break;
65  case 'filters':
66  $this->setFilters($parameters);
67  break;
68  case 'label':
69  $this->setLabel($parameters);
70  break;
71  case 'layout':
72  $this->setLayout($parameters);
73  break;
74  case 'validation':
75  $this->setValidation($parameters);
76  break;
77  }
78  }
79  }
80 
86  public function childElementsAllowed()
87  {
89  }
90 
97  protected function setAttributes(array $parameters)
98  {
99  foreach ($this->allowedAttributes as $allowedAttribute) {
100  if (isset($parameters[$allowedAttribute])) {
101  $this->configuration['attributes'][$allowedAttribute] = $parameters[$allowedAttribute];
102  } elseif (!isset($this->configuration['attributes'][$allowedAttribute])) {
103  $this->configuration['attributes'][$allowedAttribute] = '';
104  }
105  }
106  }
107 
114  protected function setFilters(array $parameters)
115  {
116  if (isset($parameters['filters.']) && is_array($parameters['filters.'])) {
117  $filters = $parameters['filters.'];
118  foreach ($filters as $key => $filterName) {
119  if ((int)$key && strpos($key, '.') === false) {
120  $filterConfiguration = [];
121  if (isset($filters[$key . '.'])) {
122  $filterConfiguration = $filters[$key . '.'];
123  }
124  $this->configuration['filters'][$filterName] = $filterConfiguration;
125  }
126  }
127  } else {
128  $this->configuration['filters'] = new \stdClass();
129  }
130  }
131 
138  protected function setLabel(array $parameters)
139  {
140  if (isset($parameters['label']) && !isset($parameters['label.'])) {
141  $this->configuration['label']['value'] = $parameters['label'];
142  } elseif (!isset($parameters['label']) && isset($parameters['label.'])) {
143  $this->configuration['label']['value'] = $parameters['label.']['value'];
144  }
145  }
146 
153  protected function setLayout(array $parameters)
154  {
155  if (isset($parameters['layout'])) {
156  if ($this->configuration['layout'] === 'front') {
157  $this->configuration['layout'] = 'back';
158  } else {
159  $this->configuration['layout'] = 'front';
160  }
161  }
162  }
163 
170  protected function setValidation(array $parameters)
171  {
172  if (isset($parameters['validation']) && is_array($parameters['validation'])) {
173  $this->configuration['validation'] = $parameters['validation'];
174  } else {
175  $this->configuration['validation'] = new \stdClass();
176  }
177  }
178 }