‪TYPO3CMS  ‪main
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 
84  public function ‪getTemplateName(): string
85  {
86  return 'UnknownElement';
87  }
88 
93  public function ‪getDefaultValue()
94  {
95  return null;
96  }
97 
104  public function ‪setDefaultValue($defaultValue) {}
105 
112  public function ‪setProperty(string $key, $value) {}
113 
117  public function ‪getProperties(): array
118  {
119  return [];
120  }
121 
125  public function ‪isRequired(): bool
126  {
127  return false;
128  }
129 }
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\getTemplateName
‪getTemplateName()
Definition: UnknownFormElement.php:84
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:30
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable
Definition: AbstractRenderable.php:42
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$type
‪string $type
Definition: AbstractRenderable.php:49
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\isRequired
‪isRequired()
Definition: UnknownFormElement.php:125
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪getRootForm()
Definition: AbstractRenderable.php:286
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:40
‪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\getProperties
‪getProperties()
Definition: UnknownFormElement.php:117
‪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:93
‪$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:55
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\initializeFormElement
‪initializeFormElement()
Definition: UnknownFormElement.php:54
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setDefaultValue
‪setDefaultValue($defaultValue)
Definition: UnknownFormElement.php:104
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement\setProperty
‪setProperty(string $key, $value)
Definition: UnknownFormElement.php:112
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:22