-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to skip saving composite fields #229
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ class LoggerFinisher extends AbstractFinisher implements LoggerAwareInterface | |
*/ | ||
protected $defaultOptions = [ | ||
'finisherVariables' => [], | ||
'includeHiddenElements' => true, | ||
'skipElementsTypes' => 'ContentElement,StaticText', | ||
]; | ||
|
||
/** | ||
|
@@ -92,8 +94,32 @@ 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() | ||
Comment on lines
+110
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment could be added in the commit description, I'd rather not have it here. |
||
($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 +134,6 @@ protected function getFormValues(): array | |
continue; | ||
} | ||
|
||
$element = $formDefinition->getElementByIdentifier($identifier); | ||
|
||
if ($element instanceof StringableFormElementInterface) { | ||
$normalizedFormValues[$identifier] = $element->valueToString($formValue); | ||
continue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the PR, this feature is nice but should be done separately. |
||
|
||
### Logging of finisher variables | ||
|
||
Additional variables stored in the `FinisherVariableProvider` can also be logged by using the `finisherVariables` option: | ||
|
||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
<trans-unit id="formEditor.elements.Form.editor.finishers.LogFormData.label"> | ||
<source>Log form data</source> | ||
</trans-unit> | ||
|
||
<trans-unit id="formEditor.elements.Form.editor.finishers.LogFormData.includeHiddenElements.label"> | ||
<source>Store composite form element data?</source> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not match the "hidden" naming of the feature. Also question marks are not necessary for checkbox labels. Finally I'd suggest this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbrodala I am not sure this is the right naming as its not about hidden elements but more about skipping functional elements. The term hidden came from the original PR as there used to be hidden elements in earelier versions.
or something simlar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, indeed, I see what you mean. Let me have a look, logging elements which cannot have values indeed doesn't make any sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright, will use my branch for now because it fits my needs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I agree. Give me some time to properly play this through. Maybe you can push another PR in the meantime for the element type filter. |
||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,7 +8,10 @@ | |||||
<source>Log form data</source> | ||||||
<target>Formulardaten loggen</target> | ||||||
</trans-unit> | ||||||
|
||||||
<trans-unit id="formEditor.elements.Form.editor.finishers.LogFormData.includeHiddenElements.label"> | ||||||
<source>Store composite form element data?</source> | ||||||
<target>Formulardaten von Composite-Elementen speichern?</target> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</trans-unit> | ||||||
</body> | ||||||
</file> | ||||||
</xliff> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to turn this into a list of strings aka
array
instead?