Skip to content
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 condition for saving hidden fields or not #33

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion Classes/Domain/Form/Finishers/LoggerFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
Expand All @@ -23,6 +24,7 @@ class LoggerFinisher extends AbstractFinisher
*/
protected $defaultOptions = [
'finisherVariables' => [],
'saveHiddenElements' => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'saveHiddenElements' => true,
'includeHiddenElements' => true,

];

/**
Expand All @@ -45,7 +47,7 @@ public function __construct(string $finisherIdentifier = '', TypoScriptFrontendC
*/
protected function executeInternal()
{
$formValues = $this->finisherContext->getFormValues();
$formValues = $this->getFormValues();
$formDefinition = $this->finisherContext->getFormRuntime()->getFormDefinition();
$data = [
'pid' => $this->frontendController->id,
Expand Down Expand Up @@ -86,6 +88,47 @@ protected function getFinisherVariables(): array
return $finisherVariables;
}

/**
* Returns all form values
* Hidden fields will be rejected, if selected in finisher.
*
* @return array
*/
protected function getFormValues(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method with this name has been added in the meantime, can you integrate your changes there?

{
$formValues = $this->finisherContext->getFormValues();

if ($this->parseOption('saveHiddenElements')) {
return $formValues;
}

$formDefinition = $this->finisherContext->getFormRuntime()->getFormDefinition();

foreach ($formValues as $formIdentifier => $value) {
$element = $formDefinition->getElementByIdentifier($formIdentifier);
$renderingOptions = $element->getRenderingOptions();

if (!$element instanceof FormElementInterface
|| (
isset($renderingOptions['_isCompositeFormElement'])
&& $renderingOptions['_isCompositeFormElement'] === true
)
|| (
isset($renderingOptions['_isHiddenFormElement'])
&& $renderingOptions['_isHiddenFormElement'] === true
)
|| (
isset($renderingOptions['_isReadOnlyFormElement'])
&& $renderingOptions['_isReadOnlyFormElement'] === true
)
Comment on lines +117 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are gone with TYPO3v10 which is the minimum TYPO3 version by now.

) {
unset($formValues[$formIdentifier]);
}
}

return $formValues;
}

/**
* Gets the current language UID
*
Expand Down
8 changes: 8 additions & 0 deletions Configuration/Form/EditorSetup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ TYPO3:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
label: 'formEditor.elements.Form.editor.finishers.LogFormData.label'
200:
identifier: 'saveHiddenElements'
templateName: 'Inspector-CheckboxEditor'
label: 'formEditor.elements.Form.editor.finishers.LogFormData.saveHiddenElements.label'
propertyPath: 'options.saveHiddenElements'

finishersDefinition:
LogFormData:
formEditor:
iconIdentifier: t3-form-icon-finisher
label: 'formEditor.elements.Form.editor.finishers.LogFormData.label'
predefinedDefaults:
options:
saveHiddenElements: true
3 changes: 3 additions & 0 deletions Resources/Private/Language/Database.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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.saveHiddenElements.label">
<source>Save hidden data?</source>
</trans-unit>

</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.Database.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<source>Log form data</source>
<target>Formulardaten loggen</target>
</trans-unit>
<trans-unit id="formEditor.elements.Form.editor.finishers.LogFormData.saveHiddenElements.label">
<source>Save hidden data?</source>
<target>Versteckte Formulardaten speichern?</target>
</trans-unit>

</body>
</file>
Expand Down