TYPO3 CMS  TYPO3_8-7
Section.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
24 
36 {
37 
41  protected $properties = [];
42 
49  public function initializeFormElement()
50  {
51  if (
52  isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
53  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
54  ) {
55  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] as $className) {
56  $hookObj = GeneralUtility::makeInstance($className);
57  if (method_exists($hookObj, 'initializeFormElement')) {
58  $hookObj->initializeFormElement(
59  $this
60  );
61  }
62  }
63  }
64  }
65 
74  public function getUniqueIdentifier(): string
75  {
76  $formDefinition = $this->getRootForm();
77  return sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
78  }
79 
88  public function getDefaultValue()
89  {
90  return null;
91  }
92 
101  public function setDefaultValue($defaultValue)
102  {
103  }
104 
111  public function getProperties(): array
112  {
113  return $this->properties;
114  }
115 
123  public function setProperty(string $key, $value)
124  {
125  if (is_array($value) && is_array($this->properties[$key])) {
126  ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
127  } else {
128  $this->properties[$key] = $value;
129  }
130  }
131 
140  public function setRenderingOption(string $key, $value)
141  {
142  $this->renderingOptions[$key] = $value;
143  }
144 
151  public function getValidators(): \SplObjectStorage
152  {
153  $formDefinition = $this->getRootForm();
154  return $formDefinition->getProcessingRule($this->getIdentifier())->getValidators();
155  }
156 
163  public function addValidator(ValidatorInterface $validator)
164  {
165  $formDefinition = $this->getRootForm();
166  $formDefinition->getProcessingRule($this->getIdentifier())->addValidator($validator);
167  }
168 
175  public function isRequired(): bool
176  {
177  foreach ($this->getValidators() as $validator) {
178  if ($validator instanceof NotEmptyValidator) {
179  return true;
180  }
181  }
182  return false;
183  }
184 }
addValidator(ValidatorInterface $validator)
Definition: Section.php:163
static makeInstance($className,... $constructorArguments)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']