Skip to content

Commit

Permalink
feat!: cleanup form output
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Jun 20, 2024
1 parent cb8ff51 commit ecb7fe3
Show file tree
Hide file tree
Showing 25 changed files with 1,256 additions and 82 deletions.
5 changes: 3 additions & 2 deletions Classes/Form/AbstractModelDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

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 = '';
protected string $valueName = '';

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 */
Expand Down
40 changes: 40 additions & 0 deletions Classes/Form/FormDefinitionDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Remind\Headless\Form;

use FriendsOfTYPO3\Headless\Form\Decorator\AbstractFormDefinitionDecorator;

class FormDefinitionDecorator extends AbstractFormDefinitionDecorator
{
private const NOT_EMPTY_ERROR_CODES = [
1221560910,
1221560718,
1347992400,
1347992453,
];
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]);
}
}
if (empty($element['properties']['validationErrorMessages'])) {
unset($element['properties']['validationErrorMessages']);
}
}
unset($element['properties']['fluidAdditionalAttributes']);
}
return $decorated;
}
}
27 changes: 26 additions & 1 deletion Configuration/Form/BaseSetup.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
75 changes: 0 additions & 75 deletions Configuration/Form/FormElementSize.yaml

This file was deleted.

95 changes: 95 additions & 0 deletions Configuration/Form/FormElements/AdvancedPassword.yaml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions Configuration/Form/FormElements/Checkbox.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit ecb7fe3

Please sign in to comment.