‪TYPO3CMS  11.5
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 
70  public function ‪getUniqueIdentifier(): string
71  {
72  $formDefinition = $this->‪getRootForm();
73  return sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
74  }
75 
83  public function ‪getDefaultValue()
84  {
85  return null;
86  }
87 
95  public function ‪setDefaultValue($defaultValue) {}
96 
102  public function ‪getProperties(): array
103  {
104  return ‪$this->properties;
105  }
106 
113  public function ‪setProperty(string $key, $value)
114  {
115  if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
116  ‪ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
117  $this->properties[$key] = ‪ArrayUtility::removeNullValuesRecursive($this->properties[$key]);
118  } elseif ($value === null) {
119  unset($this->properties[$key]);
120  } else {
121  $this->properties[$key] = $value;
122  }
123  }
124 
130  public function ‪isRequired(): bool
131  {
132  foreach ($this->‪getValidators() as ‪$validator) {
133  if (‪$validator instanceof ‪NotEmptyValidator) {
134  return true;
135  }
136  }
137  return false;
138  }
139 }
‪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:94
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section
Definition: Section.php:39
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪FormDefinition getRootForm()
Definition: AbstractRenderable.php:319
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setProperty
‪setProperty(string $key, $value)
Definition: Section.php:112
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection
Definition: AbstractSection.php:43
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:40
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getUniqueIdentifier
‪string getUniqueIdentifier()
Definition: Section.php:69
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getDefaultValue
‪mixed getDefaultValue()
Definition: Section.php:82
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getProperties
‪array getProperties()
Definition: Section.php:101
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\isRequired
‪bool isRequired()
Definition: Section.php:129
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static array removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:233
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪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