[FOLLOWUP][TASK] EXT:form - change signal slots to hooks
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Model / FormElements / UnknownFormElement.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Domain\Model\FormElements;
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
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException;
22 use TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable;
23 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
24
25 /**
26 * A Form Element that has no definition.
27 *
28 * Scope: frontend
29 */
30 class UnknownFormElement extends AbstractRenderable implements FormElementInterface
31 {
32
33 /**
34 * Constructor. Needs this FormElement's identifier and the FormElement type
35 *
36 * @param string $identifier The FormElement's identifier
37 * @param string $type The Form Element Type
38 * @throws IdentifierNotValidException
39 * @api
40 */
41 public function __construct(string $identifier, string $type)
42 {
43 if (!is_string($identifier) || strlen($identifier) === 0) {
44 throw new IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1382364370);
45 }
46 $this->identifier = $identifier;
47 $this->type = $type;
48 }
49
50 /**
51 * @return void
52 * @api
53 */
54 public function initializeFormElement()
55 {
56 if (
57 isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
58 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'])
59 ) {
60 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] as $className) {
61 $hookObj = GeneralUtility::makeInstance($className);
62 if (method_exists($hookObj, 'initializeFormElement')) {
63 $hookObj->initializeFormElement(
64 $this
65 );
66 }
67 }
68 }
69 }
70
71 /**
72 * Returns a unique identifier of this element.
73 * While element identifiers are only unique within one form,
74 * this includes the identifier of the form itself, making it "globally" unique
75 *
76 * @return string the "globally" unique identifier of this element
77 * @api
78 */
79 public function getUniqueIdentifier(): string
80 {
81 $formDefinition = $this->getRootForm();
82 $uniqueIdentifier = sprintf('%s-%s', $formDefinition->getIdentifier(), $this->identifier);
83 $uniqueIdentifier = preg_replace('/[^a-zA-Z0-9-_]/', '_', $uniqueIdentifier);
84 return lcfirst($uniqueIdentifier);
85 }
86
87 /**
88 * Get the template name of the renderable
89 *
90 * @return string
91 * @api
92 */
93 public function getTemplateName(): string
94 {
95 return 'UnknownElement';
96 }
97
98 /**
99 * @return mixed the default value for this Form Element
100 * @internal
101 */
102 public function getDefaultValue()
103 {
104 return null;
105 }
106
107 /**
108 * Not used in this implementation
109 *
110 * @param mixed $defaultValue the default value for this Form Element
111 * @internal
112 */
113 public function setDefaultValue($defaultValue)
114 {
115 }
116
117 /**
118 * Not used in this implementation
119 *
120 * @param string $key
121 * @param mixed $value
122 * @return void
123 * @internal
124 */
125 public function setProperty(string $key, $value)
126 {
127 }
128
129 /**
130 * @return array
131 * @internal
132 */
133 public function getProperties(): array
134 {
135 return [];
136 }
137
138 /**
139 * @return bool
140 * @internal
141 */
142 public function isRequired(): bool
143 {
144 return false;
145 }
146
147 /**
148 * Not used in this implementation
149 *
150 * @param FormRuntime $formRuntime
151 * @param mixed $elementValue submitted value of the element *before post processing*
152 * @param array $requestArguments submitted raw request values
153 * @return void
154 * @see FormRuntime::mapAndValidate()
155 * @internal
156 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
157 */
158 public function onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments = [])
159 {
160 GeneralUtility::logDeprecatedFunction();
161 }
162 }