From ecb7fe362a40e024f3feae6b6753ed96f1e54af2 Mon Sep 17 00:00:00 2001 From: David Mellen Date: Wed, 12 Jun 2024 13:33:20 +0200 Subject: [PATCH 1/2] feat!: cleanup form output --- Classes/Form/AbstractModelDecorator.php | 5 +- Classes/Form/FormDefinitionDecorator.php | 40 ++++++++ Configuration/Form/BaseSetup.yaml | 27 ++++- .../{ => Finishers}/JsonRedirectFinisher.yaml | 0 Configuration/Form/FormElementSize.yaml | 75 -------------- .../Form/FormElements/AdvancedPassword.yaml | 95 ++++++++++++++++++ Configuration/Form/FormElements/Checkbox.yaml | 35 +++++++ Configuration/Form/FormElements/Date.yaml | 97 ++++++++++++++++++ Configuration/Form/FormElements/Email.yaml | 95 ++++++++++++++++++ Configuration/Form/FormElements/Fieldset.yaml | 35 +++++++ Configuration/Form/FormElements/GridRow.yaml | 35 +++++++ .../Form/FormElements/MultiCheckbox.yaml | 43 ++++++++ .../Form/FormElements/MultiSelect.yaml | 43 ++++++++ Configuration/Form/FormElements/Number.yaml | 99 +++++++++++++++++++ Configuration/Form/FormElements/Password.yaml | 95 ++++++++++++++++++ .../Form/FormElements/RadioButton.yaml | 35 +++++++ .../Form/FormElements/SingleSelect.yaml | 35 +++++++ .../Form/FormElements/StaticText.yaml | 35 +++++++ .../Form/FormElements/Telephone.yaml | 95 ++++++++++++++++++ Configuration/Form/FormElements/Text.yaml | 95 ++++++++++++++++++ Configuration/Form/FormElements/Textarea.yaml | 95 ++++++++++++++++++ Configuration/Form/FormElements/Url.yaml | 95 ++++++++++++++++++ .../TypoScript/Extensions/tx_form.typoscript | 4 - .../Private/Language/de.locallang_form.xlf | 15 +++ Resources/Private/Language/locallang_form.xlf | 15 +++ 25 files changed, 1256 insertions(+), 82 deletions(-) create mode 100644 Classes/Form/FormDefinitionDecorator.php rename Configuration/Form/{ => Finishers}/JsonRedirectFinisher.yaml (100%) delete mode 100644 Configuration/Form/FormElementSize.yaml create mode 100644 Configuration/Form/FormElements/AdvancedPassword.yaml create mode 100644 Configuration/Form/FormElements/Checkbox.yaml create mode 100644 Configuration/Form/FormElements/Date.yaml create mode 100644 Configuration/Form/FormElements/Email.yaml create mode 100644 Configuration/Form/FormElements/Fieldset.yaml create mode 100644 Configuration/Form/FormElements/GridRow.yaml create mode 100644 Configuration/Form/FormElements/MultiCheckbox.yaml create mode 100644 Configuration/Form/FormElements/MultiSelect.yaml create mode 100644 Configuration/Form/FormElements/Number.yaml create mode 100644 Configuration/Form/FormElements/Password.yaml create mode 100644 Configuration/Form/FormElements/RadioButton.yaml create mode 100644 Configuration/Form/FormElements/SingleSelect.yaml create mode 100644 Configuration/Form/FormElements/StaticText.yaml create mode 100644 Configuration/Form/FormElements/Telephone.yaml create mode 100644 Configuration/Form/FormElements/Text.yaml create mode 100644 Configuration/Form/FormElements/Textarea.yaml create mode 100644 Configuration/Form/FormElements/Url.yaml diff --git a/Classes/Form/AbstractModelDecorator.php b/Classes/Form/AbstractModelDecorator.php index 72a63ad..a7178c1 100644 --- a/Classes/Form/AbstractModelDecorator.php +++ b/Classes/Form/AbstractModelDecorator.php @@ -4,10 +4,9 @@ namespace Remind\Headless\Form; -use FriendsOfTYPO3\Headless\Form\Decorator\AbstractFormDefinitionDecorator; use Psr\Http\Message\ServerRequestInterface; -abstract class AbstractModelDecorator extends AbstractFormDefinitionDecorator +abstract class AbstractModelDecorator extends FormDefinitionDecorator { protected string $actionName = ''; protected string $controllerName = ''; @@ -15,6 +14,8 @@ abstract class AbstractModelDecorator extends AbstractFormDefinitionDecorator protected function overrideDefinition(array $decorated, array $definition, int $currentPage): array { + $decorated = parent::overrideDefinition($decorated, $definition, $currentPage); + $request = $this->getRequest(); /** @var \TYPO3\CMS\Core\Routing\PageArguments $pageArguments */ diff --git a/Classes/Form/FormDefinitionDecorator.php b/Classes/Form/FormDefinitionDecorator.php new file mode 100644 index 0000000..d14b57a --- /dev/null +++ b/Classes/Form/FormDefinitionDecorator.php @@ -0,0 +1,40 @@ + $validationErrorMessage) { + if (in_array($validationErrorMessage['code'], self::NOT_EMPTY_ERROR_CODES)) { + foreach (array_keys($notEmptyValidators) as $validatorKey) { + $element['validators'][$validatorKey]['customErrorMessage'] = $validationErrorMessage['customMessage']; + } + unset($element['properties']['validationErrorMessages'][$validationErrorMessageKey]); + } + } + if (empty($element['properties']['validationErrorMessages'])) { + unset($element['properties']['validationErrorMessages']); + } + } + unset($element['properties']['fluidAdditionalAttributes']); + } + return $decorated; + } +} diff --git a/Configuration/Form/BaseSetup.yaml b/Configuration/Form/BaseSetup.yaml index 775213f..7b6937d 100644 --- a/Configuration/Form/BaseSetup.yaml +++ b/Configuration/Form/BaseSetup.yaml @@ -1,3 +1,24 @@ +imports: + - { resource: './FormElements/AdvancedPassword.yaml' } + - { resource: './FormElements/Checkbox.yaml' } + - { resource: './FormElements/Date.yaml' } + - { resource: './FormElements/Email.yaml' } + - { resource: './FormElements/GridRow.yaml' } + - { resource: './FormElements/Fieldset.yaml' } + - { resource: './FormElements/MultiCheckbox.yaml' } + - { resource: './FormElements/MultiSelect.yaml' } + - { resource: './FormElements/Number.yaml' } + - { resource: './FormElements/Password.yaml' } + - { resource: './FormElements/RadioButton.yaml' } + - { resource: './FormElements/SingleSelect.yaml' } + - { resource: './FormElements/StaticText.yaml' } + - { resource: './FormElements/Telephone.yaml' } + - { resource: './FormElements/Text.yaml' } + - { resource: './FormElements/Textarea.yaml' } + - { resource: './FormElements/Url.yaml' } + + - { resource: './Finishers/JsonRedirectFinisher.yaml' } + TYPO3: CMS: Form: @@ -10,12 +31,16 @@ TYPO3: translationFiles: 20: "EXT:rmnd_headless/Resources/Private/Language/locallang_form.xlf" formElementsDefinition: - DatePicker: null + DatePicker: + formEditor: + group: null Form: formEditor: predefinedDefaults: i18n: identifier: i18n + renderingOptions: + formDecorator: Remind\Headless\Form\FormDefinitionDecorator editors: # Overwrite submitButtonLabel propertyPath to be included in json output 300: diff --git a/Configuration/Form/JsonRedirectFinisher.yaml b/Configuration/Form/Finishers/JsonRedirectFinisher.yaml similarity index 100% rename from Configuration/Form/JsonRedirectFinisher.yaml rename to Configuration/Form/Finishers/JsonRedirectFinisher.yaml diff --git a/Configuration/Form/FormElementSize.yaml b/Configuration/Form/FormElementSize.yaml deleted file mode 100644 index dc4df14..0000000 --- a/Configuration/Form/FormElementSize.yaml +++ /dev/null @@ -1,75 +0,0 @@ -TYPO3: - CMS: - Form: - prototypes: - standard: - formElementsDefinition: - AdvancedPassword: &size - formEditor: - editors: - # Remove default Grid viewport configuration - 700: null - 701: - identifier: size - templateName: Inspector-SingleSelectEditor - label: formEditor.elements.FormElement.editor.size.label - propertyPath: properties.size - selectOptions: - 10: - value: "" - label: formEditor.elements.FormElement.editor.size.default.label - 20: - value: 25 - label: 1/4 - 30: - value: 33 - label: 1/3 - 40: - value: 50 - label: 1/2 - 50: - value: 66 - label: 2/3 - 60: - value: 75 - label: 3/4 - Checkbox: - <<: *size - ContentElement: - <<: *size - Date: - <<: *size - Email: - <<: *size - Fieldset: - <<: *size - FileUpload: - <<: *size - GridRow: - <<: *size - Hidden: - <<: *size - ImageUpload: - <<: *size - MultiCheckbox: - <<: *size - MultiSelect: - <<: *size - Number: - <<: *size - Password: - <<: *size - RadioButton: - <<: *size - SingleSelect: - <<: *size - StaticText: - <<: *size - Telephone: - <<: *size - Url: - <<: *size - Text: - <<: *size - Textarea: - <<: *size diff --git a/Configuration/Form/FormElements/AdvancedPassword.yaml b/Configuration/Form/FormElements/AdvancedPassword.yaml new file mode 100644 index 0000000..8295f73 --- /dev/null +++ b/Configuration/Form/FormElements/AdvancedPassword.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + AdvancedPassword: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Checkbox.yaml b/Configuration/Form/FormElements/Checkbox.yaml new file mode 100644 index 0000000..1897774 --- /dev/null +++ b/Configuration/Form/FormElements/Checkbox.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Checkbox: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/Date.yaml b/Configuration/Form/FormElements/Date.yaml new file mode 100644 index 0000000..5b34db1 --- /dev/null +++ b/Configuration/Form/FormElements/Date.yaml @@ -0,0 +1,97 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Date: + formEditor: + editors: + 550: + propertyPath: properties.step + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + predefinedDefaults: + properties: null + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 250: + additionalElementPropertyPaths: null + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 250: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Email.yaml b/Configuration/Form/FormElements/Email.yaml new file mode 100644 index 0000000..5227f47 --- /dev/null +++ b/Configuration/Form/FormElements/Email.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Email: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Fieldset.yaml b/Configuration/Form/FormElements/Fieldset.yaml new file mode 100644 index 0000000..8d1f5d9 --- /dev/null +++ b/Configuration/Form/FormElements/Fieldset.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Fieldset: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/GridRow.yaml b/Configuration/Form/FormElements/GridRow.yaml new file mode 100644 index 0000000..b8808a4 --- /dev/null +++ b/Configuration/Form/FormElements/GridRow.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + GridRow: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/MultiCheckbox.yaml b/Configuration/Form/FormElements/MultiCheckbox.yaml new file mode 100644 index 0000000..17b1445 --- /dev/null +++ b/Configuration/Form/FormElements/MultiCheckbox.yaml @@ -0,0 +1,43 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + MultiCheckbox: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/MultiSelect.yaml b/Configuration/Form/FormElements/MultiSelect.yaml new file mode 100644 index 0000000..49b90ea --- /dev/null +++ b/Configuration/Form/FormElements/MultiSelect.yaml @@ -0,0 +1,43 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + MultiSelect: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Number.yaml b/Configuration/Form/FormElements/Number.yaml new file mode 100644 index 0000000..fefc8ff --- /dev/null +++ b/Configuration/Form/FormElements/Number.yaml @@ -0,0 +1,99 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Number: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + 550: + propertyPath: properties.step + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + predefinedDefaults: + properties: null + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true \ No newline at end of file diff --git a/Configuration/Form/FormElements/Password.yaml b/Configuration/Form/FormElements/Password.yaml new file mode 100644 index 0000000..1497054 --- /dev/null +++ b/Configuration/Form/FormElements/Password.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Password: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/RadioButton.yaml b/Configuration/Form/FormElements/RadioButton.yaml new file mode 100644 index 0000000..02b6fae --- /dev/null +++ b/Configuration/Form/FormElements/RadioButton.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + RadioButton: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/SingleSelect.yaml b/Configuration/Form/FormElements/SingleSelect.yaml new file mode 100644 index 0000000..1bfc15e --- /dev/null +++ b/Configuration/Form/FormElements/SingleSelect.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + SingleSelect: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/StaticText.yaml b/Configuration/Form/FormElements/StaticText.yaml new file mode 100644 index 0000000..cede22d --- /dev/null +++ b/Configuration/Form/FormElements/StaticText.yaml @@ -0,0 +1,35 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + StaticText: + formEditor: + editors: + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label diff --git a/Configuration/Form/FormElements/Telephone.yaml b/Configuration/Form/FormElements/Telephone.yaml new file mode 100644 index 0000000..10deb1c --- /dev/null +++ b/Configuration/Form/FormElements/Telephone.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Telephone: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Text.yaml b/Configuration/Form/FormElements/Text.yaml new file mode 100644 index 0000000..8af3c93 --- /dev/null +++ b/Configuration/Form/FormElements/Text.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Text: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Textarea.yaml b/Configuration/Form/FormElements/Textarea.yaml new file mode 100644 index 0000000..663e7af --- /dev/null +++ b/Configuration/Form/FormElements/Textarea.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Textarea: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/Form/FormElements/Url.yaml b/Configuration/Form/FormElements/Url.yaml new file mode 100644 index 0000000..9400936 --- /dev/null +++ b/Configuration/Form/FormElements/Url.yaml @@ -0,0 +1,95 @@ +TYPO3: + CMS: + Form: + prototypes: + standard: + formElementsDefinition: + Url: + formEditor: + editors: + 400: + propertyPath: properties.placeholder + # Remove default Grid viewport configuration + 700: null + 701: + identifier: size + templateName: Inspector-SingleSelectEditor + label: formEditor.elements.FormElement.editor.size.label + propertyPath: properties.size + selectOptions: + 10: + value: "" + label: formEditor.elements.FormElement.editor.size.default.label + 20: + value: xs + label: formEditor.elements.FormElement.editor.size.xs.label + 30: + value: sm + label: formEditor.elements.FormElement.editor.size.sm.label + 40: + value: md + label: formEditor.elements.FormElement.editor.size.md.label + 50: + value: lg + label: formEditor.elements.FormElement.editor.size.lg.label + 60: + value: xl + label: formEditor.elements.FormElement.editor.size.xl.label + propertyCollections: + validators: + 10: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 20: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 30: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 40: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 50: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 60: + editors: + 200: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 70: + editors: + 200: + additionalElementPropertyPaths: null + 300: + additionalElementPropertyPaths: null + 400: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true + 80: + editors: + 300: + templateName: Inspector-TextEditor + propertyPath: customErrorMessage + doNotSetIfPropertyValueIsEmpty: true diff --git a/Configuration/TypoScript/Extensions/tx_form.typoscript b/Configuration/TypoScript/Extensions/tx_form.typoscript index 5c4bd13..a6d4102 100644 --- a/Configuration/TypoScript/Extensions/tx_form.typoscript +++ b/Configuration/TypoScript/Extensions/tx_form.typoscript @@ -2,8 +2,6 @@ plugin.tx_form { settings { yamlConfigurations { 100 = EXT:rmnd_headless/Configuration/Form/BaseSetup.yaml - 101 = EXT:rmnd_headless/Configuration/Form/FormElementSize.yaml - 102 = EXT:rmnd_headless/Configuration/Form/JsonRedirectFinisher.yaml } } } @@ -12,8 +10,6 @@ module.tx_form { settings { yamlConfigurations { 100 = EXT:rmnd_headless/Configuration/Form/BaseSetup.yaml - 101 = EXT:rmnd_headless/Configuration/Form/FormElementSize.yaml - 102 = EXT:rmnd_headless/Configuration/Form/JsonRedirectFinisher.yaml } } } \ No newline at end of file diff --git a/Resources/Private/Language/de.locallang_form.xlf b/Resources/Private/Language/de.locallang_form.xlf index a8e1e5b..235322b 100644 --- a/Resources/Private/Language/de.locallang_form.xlf +++ b/Resources/Private/Language/de.locallang_form.xlf @@ -18,6 +18,21 @@ Gesamte Breite + + Sehr klein + + + Klein + + + Mittel + + + Groß + + + Sehr groß + \ No newline at end of file diff --git a/Resources/Private/Language/locallang_form.xlf b/Resources/Private/Language/locallang_form.xlf index 18eaea3..8ba5564 100644 --- a/Resources/Private/Language/locallang_form.xlf +++ b/Resources/Private/Language/locallang_form.xlf @@ -18,6 +18,21 @@ Full Width + + Extra small + + + Small + + + Medium + + + Large + + + Extra large + \ No newline at end of file From af27e1f48c6be178d4e7fdcca07f48a581b97e28 Mon Sep 17 00:00:00 2001 From: David Mellen Date: Tue, 23 Jul 2024 13:57:34 +0200 Subject: [PATCH 2/2] feat: add links to form checkbox --- Classes/Form/FormDefinitionDecorator.php | 57 ++++++++++++++----- Configuration/Form/FormElements/Checkbox.yaml | 14 +++++ .../Private/Language/de.locallang_form.xlf | 9 +++ Resources/Private/Language/locallang_form.xlf | 9 +++ 4 files changed, 74 insertions(+), 15 deletions(-) diff --git a/Classes/Form/FormDefinitionDecorator.php b/Classes/Form/FormDefinitionDecorator.php index d14b57a..ff4d315 100644 --- a/Classes/Form/FormDefinitionDecorator.php +++ b/Classes/Form/FormDefinitionDecorator.php @@ -5,6 +5,8 @@ namespace Remind\Headless\Form; use FriendsOfTYPO3\Headless\Form\Decorator\AbstractFormDefinitionDecorator; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; class FormDefinitionDecorator extends AbstractFormDefinitionDecorator { @@ -14,27 +16,52 @@ class FormDefinitionDecorator extends AbstractFormDefinitionDecorator 1347992400, 1347992453, ]; + + private ContentObjectRenderer $cObj; + public function __construct(array $formStatus = []) + { + parent::__construct($formStatus); + $this->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); + } + protected function overrideDefinition(array $decorated, array $definition, int $currentPage): array { foreach ($decorated['elements'] as &$element) { - $notEmptyValidators = array_filter($element['validators'] ?? [], function (array $validator) { - return $validator['identifier'] === 'NotEmpty'; - }); - if ($notEmptyValidators) { - foreach ($element['properties']['validationErrorMessages'] ?? [] as $validationErrorMessageKey => $validationErrorMessage) { - if (in_array($validationErrorMessage['code'], self::NOT_EMPTY_ERROR_CODES)) { - foreach (array_keys($notEmptyValidators) as $validatorKey) { - $element['validators'][$validatorKey]['customErrorMessage'] = $validationErrorMessage['customMessage']; - } - unset($element['properties']['validationErrorMessages'][$validationErrorMessageKey]); + $this->setNotEmptyValidationErrorMessages($element); + $this->setCheckboxLinks($element); + } + return $decorated; + } + + private function setNotEmptyValidationErrorMessages(array &$element): void + { + $notEmptyValidators = array_filter($element['validators'] ?? [], function (array $validator) { + return $validator['identifier'] === 'NotEmpty'; + }); + if ($notEmptyValidators) { + foreach ($element['properties']['validationErrorMessages'] ?? [] as $validationErrorMessageKey => $validationErrorMessage) { + if (in_array($validationErrorMessage['code'], self::NOT_EMPTY_ERROR_CODES)) { + foreach (array_keys($notEmptyValidators) as $validatorKey) { + $element['validators'][$validatorKey]['customErrorMessage'] = $validationErrorMessage['customMessage']; } + unset($element['properties']['validationErrorMessages'][$validationErrorMessageKey]); } - if (empty($element['properties']['validationErrorMessages'])) { - unset($element['properties']['validationErrorMessages']); - } } - unset($element['properties']['fluidAdditionalAttributes']); + if (empty($element['properties']['validationErrorMessages'])) { + unset($element['properties']['validationErrorMessages']); + } + } + unset($element['properties']['fluidAdditionalAttributes']); + } + + private function setCheckboxLinks(array &$element): void + { + if ($element['type'] === 'Checkbox' && isset($element['properties']['links'])) { + foreach ($element['properties']['links'] as $pageUid => $label) { + $link = $this->cObj->createLink($label, ['parameter' => $pageUid])->getHtml(); + $element['label'] = sprintf($element['label'], $link); + } + unset($element['properties']['links']); } - return $decorated; } } diff --git a/Configuration/Form/FormElements/Checkbox.yaml b/Configuration/Form/FormElements/Checkbox.yaml index 1897774..9ae1421 100644 --- a/Configuration/Form/FormElements/Checkbox.yaml +++ b/Configuration/Form/FormElements/Checkbox.yaml @@ -7,6 +7,20 @@ TYPO3: Checkbox: formEditor: editors: + 300: + identifier: links + templateName: Inspector-PropertyGridEditor + label: formEditor.elements.FormElement.editor.links.label + propertyPath: properties.links + isSortable: true + enableAddRow: true + enableDeleteRow: true + useLabelAsFallbackValue: false + gridColumns: + - name: label + title: formEditor.elements.FormElement.editor.links.linkText + - name: value + title: formEditor.elements.FormElement.editor.links.pageUid # Remove default Grid viewport configuration 700: null 701: diff --git a/Resources/Private/Language/de.locallang_form.xlf b/Resources/Private/Language/de.locallang_form.xlf index 235322b..12b1262 100644 --- a/Resources/Private/Language/de.locallang_form.xlf +++ b/Resources/Private/Language/de.locallang_form.xlf @@ -12,6 +12,15 @@ Pflichtfeld Hinweis + + Links + + + Link Text + + + Seite + Größe diff --git a/Resources/Private/Language/locallang_form.xlf b/Resources/Private/Language/locallang_form.xlf index 8ba5564..7f3b871 100644 --- a/Resources/Private/Language/locallang_form.xlf +++ b/Resources/Private/Language/locallang_form.xlf @@ -12,6 +12,15 @@ Required field hint + + Links + + + Link Text + + + Page + Size