1de83774b1039fd042fc19100181944ac897a161
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Model / Json / SelectJsonElement.php
1 <?php
2 namespace TYPO3\CMS\Form\Domain\Model\Json;
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
17 /**
18 * JSON select
19 */
20 class SelectJsonElement extends \TYPO3\CMS\Form\Domain\Model\Json\AbstractJsonElement {
21
22 /**
23 * The ExtJS xtype of the element
24 *
25 * @var string
26 */
27 public $xtype = 'typo3-form-wizard-elements-basic-select';
28
29 /**
30 * The configuration array for the xtype
31 *
32 * @var array
33 */
34 public $configuration = array(
35 'attributes' => array(),
36 'filters' => array(),
37 'label' => array(
38 'value' => ''
39 ),
40 'layout' => 'front',
41 'options' => array(),
42 'validation' => array()
43 );
44
45 /**
46 * Allowed attributes for this object
47 *
48 * @var array
49 */
50 protected $allowedAttributes = array(
51 'class',
52 'disabled',
53 'id',
54 'lang',
55 'multiple',
56 'name',
57 'size',
58 'style',
59 'tabindex',
60 'title'
61 );
62
63 protected $childElementsAllowed = FALSE;
64
65 /**
66 * Set all the parameters for this object
67 *
68 * @param array $parameters Configuration array
69 * @return void
70 * @see \TYPO3\CMS\Form\Domain\Model\Json\AbstractJsonElement::setParameters()
71 */
72 public function setParameters(array $parameters) {
73 parent::setParameters($parameters);
74 $this->setOptions($parameters);
75 }
76
77 /**
78 * Set the options for this object
79 *
80 * @param array $parameters Configuration array
81 * @return void
82 */
83 protected function setOptions(array $parameters) {
84 if (is_array($parameters)) {
85 $keys = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($parameters);
86 foreach ($keys as $key) {
87 $class = $parameters[$key];
88 if ((int)$key && strpos($key, '.') === FALSE) {
89 if (isset($parameters[$key . '.']) && $class === 'OPTION') {
90 $childElementArguments = $parameters[$key . '.'];
91 if (isset($childElementArguments['selected'])) {
92 $childElementArguments['attributes']['selected'] = $childElementArguments['selected'];
93 unset($childElementArguments['selected']);
94 if (isset($childElementArguments['value'])) {
95 $childElementArguments['attributes']['value'] = $childElementArguments['value'];
96 unset($childElementArguments['value']);
97 }
98 $this->configuration['options'][] = $childElementArguments;
99 }
100 $this->configuration['options'][] = $childElementArguments;
101 }
102 }
103 }
104 }
105 }
106
107 }