2 declare(strict_types = 1);
71 $this->formSettings = GeneralUtility::makeInstance(ObjectManager::class)
72 ->get(ConfigurationManagerInterface::class)
85 if (!isset($this->formSettings[
'prototypes'][$prototypeName])) {
87 sprintf(
'The Prototype "%s" was not found.', $prototypeName),
91 return $this->formSettings[
'prototypes'][$prototypeName];
102 $returnValue = GeneralUtility::makeInstance(
103 ArrayProcessor::class,
104 $this->formSettings[
'formManager'][
'selectablePrototypesConfiguration'] ?? []
106 GeneralUtility::makeInstance(
107 ArrayProcessing::class,
108 'selectablePrototypeNames',
109 '^([\d]+)\.identifier$',
110 function ($_, $value) {
116 return array_values($returnValue[
'selectablePrototypeNames'] ?? []);
152 $subConfig = $formDefinitionValidationConfiguration[
'formElements'][$dto->
getFormElementType()] ?? [];
210 $formDefinitionValidationConfiguration[
'formElements'][$dto->
getFormElementType()][
'selectOptions'][$propertyPath]
225 bool $translated =
true
230 'No selectOptions found for form element type "%s" and property path "%s"',
242 $property = $translated ?
'selectOptions' :
'untranslatedSelectOptions';
244 return $formDefinitionValidationConfiguration[
'formElements'][$dto->
getFormElementType()][$property][$propertyPath];
281 bool $translated =
true
286 'No selectOptions found for property collection "%s" and identifier "%s" and property path "%s"',
299 $property = $translated ?
'selectOptions' :
'untranslatedSelectOptions';
316 $multiValueProperties = $formDefinitionValidationConfiguration[
'formElements'][$dto->
getFormElementType()][
'multiValueProperties'] ?? [];
317 foreach ($multiValueProperties as $multiValueProperty) {
318 if (strpos($propertyPath, $multiValueProperty) === 0) {
319 $propertyPath = $multiValueProperty;
324 return $propertyPath;
340 foreach ($multiValueProperties as $multiValueProperty) {
341 if (strpos($propertyPath, $multiValueProperty) === 0) {
342 $propertyPath = $multiValueProperty;
347 return $propertyPath;
388 'No predefinedDefaults found for form element type "%s" and property path "%s"',
400 $property = $translated ?
'predefinedDefaults' :
'untranslatedPredefinedDefaults';
442 'No predefinedDefaults found for property collection "%s" and identifier "%s" and property path "%s"',
455 $property = $translated ?
'predefinedDefaults' :
'untranslatedPredefinedDefaults';
479 return $formDefinitionValidationConfiguration[
'formElements'][$dto->
getFormElementType()][
'creatable'] ??
false;
514 $prototypeConfiguration,
529 foreach ($keys as $key) {
530 if (!is_string($key)) {
537 return $translations;
549 $translationFiles = $prototypeConfiguration[
'formEditor'][
'translationFile'] ?? [];
550 if (is_string($translationFiles)) {
551 $translationFiles = [$translationFiles];
570 $cacheKey = implode(
'_', [
'buildFormDefinitionValidationConfigurationFromFormEditorSetup', $prototypeName]);
573 if ($configuration ===
null) {
575 $extractorDto = GeneralUtility::makeInstance(ExtractorDto::class, $prototypeConfiguration);
577 GeneralUtility::makeInstance(ArrayProcessor::class, $prototypeConfiguration)->forEach(
578 GeneralUtility::makeInstance(
579 ArrayProcessing::class,
580 'formElementPropertyPaths',
581 '^formElementsDefinition\.(.*)\.formEditor\.editors\.([\d]+)\.(propertyPath|.*\.propertyPath)$',
582 GeneralUtility::makeInstance(PropertyPathsExtractor::class, $extractorDto)
584 GeneralUtility::makeInstance(
585 ArrayProcessing::class,
586 'formElementAdditionalElementPropertyPaths',
587 '^formElementsDefinition\.(.*)\.formEditor\.editors\.([\d]+)\.additionalElementPropertyPaths\.([\d]+)',
588 GeneralUtility::makeInstance(AdditionalElementPropertyPathsExtractor::class, $extractorDto)
590 GeneralUtility::makeInstance(
591 ArrayProcessing::class,
592 'formElementRelativeMultiValueProperties',
593 '^formElementsDefinition\.(.*)\.formEditor\.editors\.([\d]+)\.templateName$',
594 GeneralUtility::makeInstance(MultiValuePropertiesExtractor::class, $extractorDto)
596 GeneralUtility::makeInstance(
597 ArrayProcessing::class,
598 'formElementSelectOptions',
599 '^formElementsDefinition\.(.*)\.formEditor\.editors\.([\d]+)\.selectOptions\.([\d]+)\.value$',
600 GeneralUtility::makeInstance(SelectOptionsExtractor::class, $extractorDto)
602 GeneralUtility::makeInstance(
603 ArrayProcessing::class,
604 'formElementPredefinedDefaults',
605 '^formElementsDefinition\.(.*)\.formEditor\.predefinedDefaults\.(.+)$',
606 GeneralUtility::makeInstance(PredefinedDefaultsExtractor::class, $extractorDto)
608 GeneralUtility::makeInstance(
609 ArrayProcessing::class,
610 'formElementCreatable',
611 '^formElementsDefinition\.(.*)\.formEditor.group$',
612 GeneralUtility::makeInstance(IsCreatableFormElementExtractor::class, $extractorDto)
614 GeneralUtility::makeInstance(
615 ArrayProcessing::class,
616 'propertyCollectionCreatable',
617 '^formElementsDefinition\.(.*)\.formEditor\.editors\.([\d]+)\.templateName$',
618 GeneralUtility::makeInstance(IsCreatablePropertyCollectionElementExtractor::class, $extractorDto)
620 GeneralUtility::makeInstance(
621 ArrayProcessing::class,
622 'propertyCollectionPropertyPaths',
623 '^formElementsDefinition\.(.*)\.formEditor\.propertyCollections\.(finishers|validators)\.([\d]+)\.editors\.([\d]+)\.(propertyPath|.*\.propertyPath)$',
624 GeneralUtility::makeInstance(CollectionPropertyPathsExtractor::class, $extractorDto)
626 GeneralUtility::makeInstance(
627 ArrayProcessing::class,
628 'propertyCollectionAdditionalElementPropertyPaths',
629 '^formElementsDefinition\.(.*)\.formEditor\.propertyCollections\.(finishers|validators)\.([\d]+)\.editors\.([\d]+)\.additionalElementPropertyPaths\.([\d]+)',
630 GeneralUtility::makeInstance(AdditionalElementPropertyPathsExtractor::class, $extractorDto)
632 GeneralUtility::makeInstance(
633 ArrayProcessing::class,
634 'propertyCollectionRelativeMultiValueProperties',
635 '^formElementsDefinition\.(.*)\.formEditor\.propertyCollections\.(finishers|validators)\.([\d]+)\.editors\.([\d]+)\.templateName$',
636 GeneralUtility::makeInstance(CollectionMultiValuePropertiesExtractor::class, $extractorDto)
638 GeneralUtility::makeInstance(
639 ArrayProcessing::class,
640 'propertyCollectionSelectOptions',
641 '^formElementsDefinition\.(.*)\.formEditor\.propertyCollections\.(finishers|validators)\.([\d]+)\.editors\.([\d]+)\.selectOptions\.([\d]+)\.value$',
642 GeneralUtility::makeInstance(CollectionSelectOptionsExtractor::class, $extractorDto)
644 GeneralUtility::makeInstance(
645 ArrayProcessing::class,
646 'propertyCollectionPredefinedDefaults',
647 '^(validatorsDefinition|finishersDefinition)\.(.*)\.formEditor\.predefinedDefaults\.(.+)$',
648 GeneralUtility::makeInstance(CollectionPredefinedDefaultsExtractor::class, $extractorDto)
651 $configuration = $extractorDto->getResult();
653 $configuration = $this->
translateValues($prototypeConfiguration, $configuration);
663 return $configuration;
697 string $prototypeName,
700 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'ext/form'][
'buildFormDefinitionValidationConfiguration'] ?? [] as $className) {
701 $hookObj = GeneralUtility::makeInstance($className);
702 if (method_exists($hookObj,
'addAdditionalPropertyPaths')) {
703 $validationDto = GeneralUtility::makeInstance(ValidationDto::class, $prototypeName);
704 $propertyPathsFromHook = $hookObj->addAdditionalPropertyPaths($validationDto);
705 if (!is_array($propertyPathsFromHook)) {
706 $message =
'Return value of "%s->addAdditionalPropertyPaths() must be type "array"';
712 $propertyPathsFromHook,
718 return $configuration;
730 string $hookClassName,
731 string $prototypeName,
732 array $propertyPathsFromHook,
735 foreach ($propertyPathsFromHook as $index => $validationDto) {
737 $message =
'Return value of "%s->addAdditionalPropertyPaths()[%s] must be an instance of "%s"';
739 sprintf($message, $hookClassName, $index, ValidationDto::class),
744 if ($validationDto->getPrototypeName() !== $prototypeName) {
745 $message =
'The prototype name "%s" does not match "%s" on "%s->addAdditionalPropertyPaths()[%s]';
749 $validationDto->getPrototypeName(),
759 $formElementType = $validationDto->getFormElementType();
761 $message =
'Form element type "%s" does not exists in prototype configuration "%s"';
763 sprintf($message, $formElementType, $validationDto->getPrototypeName()),
768 if ($validationDto->hasPropertyCollectionName() &&
769 $validationDto->hasPropertyCollectionElementIdentifier()) {
770 $propertyCollectionName = $validationDto->getPropertyCollectionName();
771 $propertyCollectionElementIdentifier = $validationDto->getPropertyCollectionElementIdentifier();
773 if ($propertyCollectionName !==
'finishers' && $propertyCollectionName !==
'validators') {
774 $message =
'The property collection name "%s" for form element "%s" must be "finishers" or "validators"';
776 sprintf($message, $propertyCollectionName, $formElementType),
781 $configuration[
'formElements'][$formElementType][
'collections'][$propertyCollectionName][$propertyCollectionElementIdentifier][
'additionalPropertyPaths'][]
782 = $validationDto->getPropertyPath();
784 $configuration[
'formElements'][$formElementType][
'additionalPropertyPaths'][]
785 = $validationDto->getPropertyPath();
789 return $configuration;
799 if (empty($subConfig)) {
803 in_array($propertyPath, $subConfig[
'propertyPaths'] ?? [],
true)
804 || in_array($propertyPath, $subConfig[
'additionalElementPropertyPaths'] ?? [],
true)
805 || in_array($propertyPath, $subConfig[
'additionalPropertyPaths'] ?? [],
true)
809 foreach ($subConfig[
'multiValueProperties'] ?? [] as $relativeMultiValueProperty) {
810 if (strpos($propertyPath, $relativeMultiValueProperty) === 0) {
823 protected function translateValues(array $prototypeConfiguration, array $configuration): array
825 if (isset($configuration[
'formElements'])) {
827 $prototypeConfiguration,
828 $configuration[
'formElements']
832 $prototypeConfiguration,
833 $configuration[
'formElements']
837 foreach ($configuration[
'collections'] ?? [] as $name => $collections) {
839 $configuration[
'collections'][$name] = $this->
translateSelectOptions($prototypeConfiguration, $configuration[
'collections'][$name]);
841 return $configuration;
851 foreach ($formElements ?? [] as $name => $formElement) {
852 if (!isset($formElement[
'predefinedDefaults'])) {
855 $formElement[
'untranslatedPredefinedDefaults'] = $formElement[
'predefinedDefaults'];
857 $formElement[
'predefinedDefaults'],
858 $prototypeConfiguration[
'formEditor'][
'translationFile'] ??
null
860 $formElements[$name] = $formElement;
862 return $formElements;
872 foreach ($formElements ?? [] as $name => $formElement) {
873 if (empty($formElement[
'selectOptions']) || !is_array($formElement[
'selectOptions'])) {
876 $formElement[
'untranslatedSelectOptions'] = $formElement[
'selectOptions'];
879 $formElement[
'selectOptions'],
880 $prototypeConfiguration[
'formEditor'][
'translationFiles'] ?? []
882 $formElements[$name] = $formElement;
884 return $formElements;
893 if (isset($this->firstLevelCache[$cacheKey])) {
894 return $this->firstLevelCache[$cacheKey];
908 $this->firstLevelCache[$cacheKey] = $value;
917 ? $this->translationService
926 return GeneralUtility::makeInstance(CacheManager::class)->getCache(
'assets');