‪TYPO3CMS  10.4
UnknownFormElement.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 
34 {
35 
43  public function ‪__construct(string ‪$identifier, string ‪$type)
44  {
45  if (!is_string(‪$identifier) || strlen(‪$identifier) === 0) {
46  throw new ‪IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1382364370);
47  }
48  $this->identifier = ‪$identifier;
49  $this->type = ‪$type;
50  }
51 
55  public function ‪initializeFormElement()
56  {
57  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] ?? [] as $className) {
58  $hookObj = GeneralUtility::makeInstance($className);
59  if (method_exists($hookObj, 'initializeFormElement')) {
60  $hookObj->initializeFormElement(
61  $this
62  );
63  }
64  }
65  }
66 
74  public function ‪getUniqueIdentifier(): string
75  {
76  $formDefinition = $this->‪getRootForm();
77  $uniqueIdentifier = sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
78  $uniqueIdentifier = (string)preg_replace('/[^a-zA-Z0-9-_]/', '_', $uniqueIdentifier);
79  return lcfirst($uniqueIdentifier);
80  }
81 
87  public function ‪getTemplateName(): string
88  {
89  return 'UnknownElement';
90  }
91 
96  public function ‪getDefaultValue()
97  {
98  return null;
99  }
100 
107  public function ‪setDefaultValue($defaultValue)
108  {
109  }
110 
118  public function ‪setProperty(string $key, $value)
119  {
120  }
121 
126  public function ‪getProperties(): array
127  {
128  return [];
129  }
130 
135  public function ‪isRequired(): bool
136  {
137  return false;
138  }
139 }
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:31
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\isRequired
‪bool isRequired()
Definition: UnknownFormElement.php:135
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable
Definition: AbstractRenderable.php:42
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$type
‪string $type
Definition: AbstractRenderable.php:50
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪FormDefinition getRootForm()
Definition: AbstractRenderable.php:318
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:40
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getTemplateName
‪string getTemplateName()
Definition: UnknownFormElement.php:87
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getProperties
‪array getProperties()
Definition: UnknownFormElement.php:126
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getUniqueIdentifier
‪string getUniqueIdentifier()
Definition: UnknownFormElement.php:74
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement
Definition: UnknownFormElement.php:34
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\__construct
‪__construct(string $identifier, string $type)
Definition: UnknownFormElement.php:43
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getDefaultValue
‪mixed getDefaultValue()
Definition: UnknownFormElement.php:96
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$identifier
‪string $identifier
Definition: AbstractRenderable.php:56
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\initializeFormElement
‪initializeFormElement()
Definition: UnknownFormElement.php:55
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setDefaultValue
‪setDefaultValue($defaultValue)
Definition: UnknownFormElement.php:107
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setProperty
‪setProperty(string $key, $value)
Definition: UnknownFormElement.php:118
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:22