‪TYPO3CMS  11.5
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 {
42  public function ‪__construct(string ‪$identifier, string ‪$type)
43  {
44  if (!is_string(‪$identifier) || strlen(‪$identifier) === 0) {
45  throw new ‪IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1382364370);
46  }
47  $this->identifier = ‪$identifier;
48  $this->type = ‪$type;
49  }
50 
54  public function ‪initializeFormElement()
55  {
56  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] ?? [] as $className) {
57  $hookObj = GeneralUtility::makeInstance($className);
58  if (method_exists($hookObj, 'initializeFormElement')) {
59  $hookObj->initializeFormElement(
60  $this
61  );
62  }
63  }
64  }
65 
73  public function ‪getUniqueIdentifier(): string
74  {
75  $formDefinition = $this->‪getRootForm();
76  $uniqueIdentifier = sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
77  $uniqueIdentifier = (string)preg_replace('/[^a-zA-Z0-9-_]/', '_', $uniqueIdentifier);
78  return lcfirst($uniqueIdentifier);
79  }
80 
86  public function ‪getTemplateName(): string
87  {
88  return 'UnknownElement';
89  }
90 
95  public function ‪getDefaultValue()
96  {
97  return null;
98  }
99 
106  public function ‪setDefaultValue($defaultValue) {}
107 
115  public function ‪setProperty(string $key, $value) {}
116 
121  public function ‪getProperties(): array
122  {
123  return [];
124  }
125 
130  public function ‪isRequired(): bool
131  {
132  return false;
133  }
134 }
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:30
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\isRequired
‪bool isRequired()
Definition: UnknownFormElement.php:130
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable
Definition: AbstractRenderable.php:41
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$type
‪string $type
Definition: AbstractRenderable.php:48
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪FormDefinition getRootForm()
Definition: AbstractRenderable.php:319
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:40
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getTemplateName
‪string getTemplateName()
Definition: UnknownFormElement.php:86
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getProperties
‪array getProperties()
Definition: UnknownFormElement.php:121
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getUniqueIdentifier
‪string getUniqueIdentifier()
Definition: UnknownFormElement.php:73
‪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:42
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getDefaultValue
‪mixed getDefaultValue()
Definition: UnknownFormElement.php:95
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$identifier
‪string $identifier
Definition: AbstractRenderable.php:54
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\initializeFormElement
‪initializeFormElement()
Definition: UnknownFormElement.php:54
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setDefaultValue
‪setDefaultValue($defaultValue)
Definition: UnknownFormElement.php:106
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setProperty
‪setProperty(string $key, $value)
Definition: UnknownFormElement.php:115
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:22