‪TYPO3CMS  10.4
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 {
40 
44  protected ‪$properties = [];
45 
52  public function ‪initializeFormElement()
53  {
54  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] ?? [] as $className) {
55  $hookObj = GeneralUtility::makeInstance($className);
56  if (method_exists($hookObj, 'initializeFormElement')) {
57  $hookObj->initializeFormElement(
58  $this
59  );
60  }
61  }
62  }
63 
71  public function ‪getUniqueIdentifier(): string
72  {
73  $formDefinition = $this->‪getRootForm();
74  return sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
75  }
76 
84  public function ‪getDefaultValue()
85  {
86  return null;
87  }
88 
96  public function ‪setDefaultValue($defaultValue)
97  {
98  }
99 
105  public function ‪getProperties(): array
106  {
107  return ‪$this->properties;
108  }
109 
116  public function ‪setProperty(string $key, $value)
117  {
118  if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
119  ‪ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
120  $this->properties[$key] = ‪ArrayUtility::removeNullValuesRecursive($this->properties[$key]);
121  } elseif ($value === null) {
122  unset($this->properties[$key]);
123  } else {
124  $this->properties[$key] = $value;
125  }
126  }
127 
133  public function ‪isRequired(): bool
134  {
135  foreach ($this->‪getValidators() as ‪$validator) {
136  if (‪$validator instanceof ‪NotEmptyValidator) {
137  return true;
138  }
139  }
140  return false;
141  }
142 }
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\$properties
‪array $properties
Definition: Section.php:43
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setDefaultValue
‪setDefaultValue($defaultValue)
Definition: Section.php:95
‪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:318
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\setProperty
‪setProperty(string $key, $value)
Definition: Section.php:115
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection
Definition: AbstractSection.php:44
‪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:70
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getDefaultValue
‪mixed getDefaultValue()
Definition: Section.php:83
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\getProperties
‪array getProperties()
Definition: Section.php:104
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\isRequired
‪bool isRequired()
Definition: Section.php:132
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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:46
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section\initializeFormElement
‪initializeFormElement()
Definition: Section.php:51
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface\getValidators
‪SplObjectStorage< ValidatorInterface > getValidators()
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:22