TYPO3 CMS  TYPO3_8-7
AbstractFormElement.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 
26 
47 {
48 
52  protected $properties = [];
53 
62  public function __construct(string $identifier, string $type)
63  {
64  if (!is_string($identifier) || strlen($identifier) === 0) {
65  throw new IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1477082502);
66  }
67  $this->identifier = $identifier;
68  $this->type = $type;
69  }
70 
76  public function initializeFormElement()
77  {
78  if (
79  isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
80  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
81  ) {
82  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] as $className) {
83  $hookObj = GeneralUtility::makeInstance($className);
84  if (method_exists($hookObj, 'initializeFormElement')) {
85  $hookObj->initializeFormElement(
86  $this
87  );
88  }
89  }
90  }
91  }
92 
99  public function getUniqueIdentifier(): string
100  {
101  $formDefinition = $this->getRootForm();
102  $uniqueIdentifier = sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
103  $uniqueIdentifier = preg_replace('/[^a-zA-Z0-9_-]/', '_', $uniqueIdentifier);
104  return lcfirst($uniqueIdentifier);
105  }
106 
113  public function getDefaultValue()
114  {
115  $formDefinition = $this->getRootForm();
116  return $formDefinition->getElementDefaultValueByIdentifier($this->identifier);
117  }
118 
125  public function setDefaultValue($defaultValue)
126  {
127  $formDefinition = $this->getRootForm();
128  $formDefinition->addElementDefaultValue($this->identifier, $defaultValue);
129  }
130 
137  public function isRequired(): bool
138  {
139  foreach ($this->getValidators() as $validator) {
140  if ($validator instanceof NotEmptyValidator) {
141  return true;
142  }
143  }
144  return false;
145  }
146 
154  public function setProperty(string $key, $value)
155  {
156  if (is_array($value) && is_array($this->properties[$key])) {
157  ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
158  } else {
159  $this->properties[$key] = $value;
160  }
161  }
162 
169  public function getProperties(): array
170  {
171  return $this->properties;
172  }
173 
183  public function onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments = [])
184  {
186  }
187 }
onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments=[])
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']