diff --git a/Classes/Domain/Form/Finishers/LoggerFinisher.php b/Classes/Domain/Form/Finishers/LoggerFinisher.php index bfc7e6c..bf10560 100644 --- a/Classes/Domain/Form/Finishers/LoggerFinisher.php +++ b/Classes/Domain/Form/Finishers/LoggerFinisher.php @@ -18,6 +18,7 @@ use TYPO3\CMS\Extbase\Domain\Model\FileReference as ExtbaseFileReference; use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher; use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException; +use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface; use TYPO3\CMS\Form\Domain\Model\FormElements\StringableFormElementInterface; /** @@ -32,6 +33,8 @@ class LoggerFinisher extends AbstractFinisher implements LoggerAwareInterface */ protected $defaultOptions = [ 'finisherVariables' => [], + 'includeHiddenElements' => true, + 'skipElementsTypes' => 'ContentElement,StaticText', ]; /** @@ -92,8 +95,33 @@ protected function getFormValues(): array { $normalizedFormValues = []; $formDefinition = $this->finisherContext->getFormRuntime()->getFormDefinition(); + $skipHiddenElements = !$this->parseOption('includeHiddenElements'); + $skipElementTypes = GeneralUtility::trimExplode(',', $this->parseOption('skipElementsTypes')); foreach ($this->finisherContext->getFormValues() as $identifier => $formValue) { + + $element = $formDefinition->getElementByIdentifier($identifier); + $elementType = null; + if ($element !== null) { + $renderingOptions = $element->getRenderingOptions(); + $elementType = $element->getType(); + } + if ( + $skipHiddenElements && + ( + // Mimik the logik of \TYPO3\CMS\Form\Domain\Finishers\EmailFinisher + // with conditions against {formValue.value} and {formValue.isSection} in + // EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/Default.html + // where {formValue.isSection} is set in \TYPO3\CMS\Form\ViewHelpers\RenderFormValueViewHelper::renderStatic() + ($renderingOptions['_isCompositeFormElement'] ?? false) + || ($renderingOptions['_isSection'] ?? false) + // additionally skip configurable element types which don't actually have form values (e.g. StaticText) + || in_array($elementType, $skipElementTypes) + ) + ) { + continue; + } + if (is_object($formValue)) { if ($formValue instanceof ExtbaseFileReference) { $formValue = $formValue->getOriginalResource(); @@ -108,8 +136,6 @@ protected function getFormValues(): array continue; } - $element = $formDefinition->getElementByIdentifier($identifier); - if ($element instanceof StringableFormElementInterface) { $normalizedFormValues[$identifier] = $element->valueToString($formValue); continue; diff --git a/Configuration/Form/Setup.yaml b/Configuration/Form/Setup.yaml index 1e3e4a8..9832673 100644 --- a/Configuration/Form/Setup.yaml +++ b/Configuration/Form/Setup.yaml @@ -22,6 +22,11 @@ TYPO3: identifier: header templateName: Inspector-CollectionElementHeaderEditor label: formEditor.elements.Form.editor.finishers.LogFormData.label + 200: + identifier: 'includeHiddenElements' + templateName: 'Inspector-CheckboxEditor' + label: 'formEditor.elements.Form.editor.finishers.LogFormData.includeHiddenElements.label' + propertyPath: 'options.includeHiddenElements' 9999: identifier: removeButton templateName: Inspector-RemoveElementEditor @@ -32,3 +37,7 @@ TYPO3: formEditor: iconIdentifier: form-finisher label: formEditor.elements.Form.editor.finishers.LogFormData.label + predefinedDefaults: + options: + includeHiddenElements: true + skipElementsTypes: 'ContentElement,StaticText' diff --git a/README.md b/README.md index 86c47e7..ad8af78 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,18 @@ finishers: The `LogFormData` finisher should be the last finisher or right before the `Redirect` finisher if used. Logging after a redirect is not possible. +## Configuration + +### Save values from hidden or composite Elements + +Some form elements, such as fieldsets or other containers, do not hold a form value by themselves; only their child elements hold values. By default, all form elements are saved, even those that never contain values, which can result in empty columns in the log records and exports. + +To prevent this, set the finisher option `includeHiddenElements` to `false`. This option ensures that values from composite elements are not saved, similar to how the `EmailFinisher` only includes fields in emails that actually contain a value. + +Additionally, you can use the finisher option `skipElementsTypes` to exclude specific form elements (comma separated list). By default, this option excludes `ContentElement` and `StaticText` elements, as they will never have a value. + +### Logging of finisher variables + Additional variables stored in the `FinisherVariableProvider` can also be logged by using the `finisherVariables` option: ``` diff --git a/Resources/Private/Language/Database.xlf b/Resources/Private/Language/Database.xlf index d713e2b..5fd78e5 100644 --- a/Resources/Private/Language/Database.xlf +++ b/Resources/Private/Language/Database.xlf @@ -7,7 +7,9 @@ Log form data - + + Store composite form element data? + diff --git a/Resources/Private/Language/de.Database.xlf b/Resources/Private/Language/de.Database.xlf index 61a9e4a..48edb95 100644 --- a/Resources/Private/Language/de.Database.xlf +++ b/Resources/Private/Language/de.Database.xlf @@ -8,7 +8,10 @@ Log form data Formulardaten loggen - + + Store composite form element data? + Formulardaten von Composite-Elementen speichern? +