‪TYPO3CMS  ‪main
Section.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 /*
19  * Inspired by and partially taken from the Neos.Form package (www.neos.io)
20  */
21 
23 
27 
39 {
43  protected ‪$properties = [];
44 
51  public function ‪initializeFormElement()
52  {
53  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] ?? [] as $className) {
54  $hookObj = GeneralUtility::makeInstance($className);
55  if (method_exists($hookObj, 'initializeFormElement')) {
56  $hookObj->initializeFormElement(
57  $this
58  );
59  }
60  }
61  }
62 
63  public function ‪setOptions(array $options, bool $resetValidators = false)
64  {
65  if (isset($options['properties'])) {
66  foreach ($options['properties'] as $key => $value) {
67  $this->‪setProperty($key, $value);
68  }
69  }
70 
71  parent::setOptions($options, $resetValidators);
72  }
73 
81  public function ‪getUniqueIdentifier(): string
82  {
83  $formDefinition = $this->‪getRootForm();
84  return sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
85  }
86 
94  public function ‪getDefaultValue()
95  {
96  return null;
97  }
98 
106  public function ‪setDefaultValue($defaultValue) {}
107 
111  public function ‪getProperties(): array
112  {
113  return ‪$this->properties;
114  }
115 
121  public function ‪setProperty(string $key, $value)
122  {
123  if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
124  ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
125  $this->properties[$key] = ‪ArrayUtility::removeNullValuesRecursive($this->properties[$key]);
126  } elseif ($value === null) {
127  unset($this->properties[$key]);
128  } else {
129  $this->properties[$key] = $value;
130  }
131  }
132 
136  public function ‪isRequired(): bool
137  {
138  foreach ($this->‪getValidators() as ‪$validator) {
139  if (‪$validator instanceof NotEmptyValidator) {
140  return true;
141  }
142  }
143  return false;
144  }
145 }
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\$properties
‪array $properties
Definition: Section.php:42
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setDefaultValue
‪setDefaultValue($defaultValue)
Definition: Section.php:105
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section
Definition: Section.php:39
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setProperty
‪setProperty(string $key, $value)
Definition: Section.php:120
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:222
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection
Definition: AbstractSection.php:43
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪getRootForm()
Definition: AbstractRenderable.php:286
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:40
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\isRequired
‪isRequired()
Definition: Section.php:135
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:262
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getUniqueIdentifier
‪string getUniqueIdentifier()
Definition: Section.php:80
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getProperties
‪getProperties()
Definition: Section.php:110
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getDefaultValue
‪mixed getDefaultValue()
Definition: Section.php:93
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setOptions
‪setOptions(array $options, bool $resetValidators=false)
Definition: Section.php:62
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\initializeFormElement
‪initializeFormElement()
Definition: Section.php:50
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface\getValidators
‪SplObjectStorage< ValidatorInterface > getValidators()
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:22