2 declare(strict_types = 1);
136 public function setOptions(array $options,
bool $resetValidators =
false)
138 if (isset($options[
'label'])) {
142 if (isset($options[
'defaultValue'])) {
143 $this->setDefaultValue($options[
'defaultValue']);
146 if (isset($options[
'properties'])) {
147 foreach ($options[
'properties'] as $key => $value) {
148 $this->setProperty($key, $value);
152 if (isset($options[
'renderingOptions'])) {
153 foreach ($options[
'renderingOptions'] as $key => $value) {
158 if (isset($options[
'validators'])) {
159 $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache(
'cache_runtime');
160 $configurationHashes = $runtimeCache->get(
'formAbstractRenderableConfigurationHashes') ?: [];
162 if ($resetValidators) {
167 $configurationHashes = [];
170 foreach ($options[
'validators'] as $validatorConfiguration) {
171 $configurationHash = md5(
172 spl_object_hash($this) .
173 json_encode($validatorConfiguration)
175 if (in_array($configurationHash, $configurationHashes)) {
178 $this->
createValidator($validatorConfiguration[
'identifier'], $validatorConfiguration[
'options'] ?? []);
179 $configurationHashes[] = $configurationHash;
180 $runtimeCache->set(
'formAbstractRenderableConfigurationHashes', $configurationHashes);
184 if (isset($options[
'variants'])) {
185 foreach ($options[
'variants'] as $variantConfiguration) {
192 [
'label',
'defaultValue',
'properties',
'renderingOptions',
'validators',
'formEditor',
'variants']
204 public function createValidator(
string $validatorIdentifier, array $options = [])
207 if (isset($validatorsDefinition[$validatorIdentifier]) && is_array($validatorsDefinition[$validatorIdentifier]) && isset($validatorsDefinition[$validatorIdentifier][
'implementationClassName'])) {
208 $implementationClassName = $validatorsDefinition[$validatorIdentifier][
'implementationClassName'];
209 $defaultOptions = $validatorsDefinition[$validatorIdentifier][
'options'] ?? [];
213 $validator = GeneralUtility::makeInstance(ObjectManager::class)
214 ->get($implementationClassName, $defaultOptions);
218 throw new ValidatorPresetNotFoundException(
'The validator preset identified by "' . $validatorIdentifier .
'" could not be found, or the implementationClassName was not specified.', 1328710202);
229 $formDefinition->getProcessingRule($this->
getIdentifier())->addValidator($validator);
241 return $formDefinition->getProcessingRule($this->
getIdentifier())->getValidators();
252 $formDefinition->getProcessingRule($this->
getIdentifier())->setDataType($dataType);
284 if (is_array($value) && isset($this->renderingOptions[$key]) && is_array($this->renderingOptions[$key])) {
287 } elseif ($value ===
null) {
288 unset($this->renderingOptions[$key]);
290 $this->renderingOptions[$key] = $value;
324 while ($rootRenderable !==
null && !($rootRenderable instanceof
FormDefinition)) {
327 if ($rootRenderable ===
null) {
331 return $rootRenderable;
343 $rootForm->registerRenderable($this);
355 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'ext/form'][
'beforeRemoveFromParentRenderable'] ?? [] as $className) {
356 $hookObj = GeneralUtility::makeInstance($className);
357 if (method_exists($hookObj,
'beforeRemoveFromParentRenderable')) {
358 $hookObj->beforeRemoveFromParentRenderable(
366 $rootForm->unregisterRenderable($this);
367 }
catch (FormDefinitionConsistencyException $exception) {
369 $this->parentRenderable =
null;
421 return empty($this->renderingOptions[
'templateName'])
423 : $this->renderingOptions[
'templateName'];
433 return !isset($this->renderingOptions[
'enabled']) || (bool)$this->renderingOptions[
'enabled'] ===
true;
453 unset($options[
'identifier']);
455 $variant = GeneralUtility::makeInstance(ObjectManager::class)
456 ->get(RenderableVariant::class,
$identifier, $options, $this);