From 85b00d0d51b7fbdb31e403653e470190cb592798 Mon Sep 17 00:00:00 2001 From: Andreas Kienast <a.fernandez@scripting-base.de> Date: Thu, 21 Mar 2024 09:49:27 +0100 Subject: [PATCH] [TASK] Do not render `typo3-formengine-updater` if linked field is hidden TYPO3's TCA type field is rendered in the FormEngine along with a `<typo3-formengine-updater>` element that listens on changes on the linked type field. This is a rare case: if FormEngine is programmatically rendered via an own controller and the value of the `type` field is hardcoded via `overrideValues` in the FormEngine compiler, the field itself is not rendered. However, the `<typo3-formengine-updater>` element is still there, leaving an "empty" field group. This patch now checks whether something is available for rendering before rendering the `<typo3-formengine-updater>` element. Resolves: #103449 Releases: main Change-Id: I708b49665dfaa5b836954e40e99cbcb9ed44ec03 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83554 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Benjamin Franzke <ben@bnf.dev> Reviewed-by: Benjamin Franzke <ben@bnf.dev> --- .../Form/Container/SingleFieldContainer.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php b/typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php index 69ddbac225c4..3ba6d1b9f214 100644 --- a/typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php +++ b/typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php @@ -130,18 +130,19 @@ class SingleFieldContainer extends AbstractContainer $options['renderType'] = $parameterArray['fieldConf']['config']['type']; } $resultArray = $this->nodeFactory->create($options)->render(); - - // Render a custom HTML element which will ask the user to save/update the form due to changing the element. - // This is used for eg. "type" fields and others configured with "onChange" - // (https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Properties/OnChange.html) - $requestFormEngineUpdate = - (!empty($this->data['processedTca']['ctrl']['type']) && $fieldName === $typeField) - || (isset($parameterArray['fieldConf']['onChange']) && $parameterArray['fieldConf']['onChange'] === 'reload'); - if ($requestFormEngineUpdate) { - $askForUpdate = $backendUser->jsConfirmation(JsConfirmation::TYPE_CHANGE); - $requestMode = $askForUpdate ? 'ask' : 'enforce'; - $fieldSelector = sprintf('[name="%s"]', $parameterArray['itemFormElName']); - $resultArray['html'] .= '<typo3-formengine-updater mode="' . htmlspecialchars($requestMode) . '" field="' . htmlspecialchars($fieldSelector) . '"></typo3-formengine-updater>'; + if ($resultArray['html'] !== '') { + // Render a custom HTML element which will ask the user to save/update the form due to changing the element. + // This is used for e.g. "type" fields and others configured with "onChange" + // (https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Properties/OnChange.html) + $requestFormEngineUpdate = + (!empty($this->data['processedTca']['ctrl']['type']) && $fieldName === $typeField) + || (isset($parameterArray['fieldConf']['onChange']) && $parameterArray['fieldConf']['onChange'] === 'reload'); + if ($requestFormEngineUpdate) { + $askForUpdate = $backendUser->jsConfirmation(JsConfirmation::TYPE_CHANGE); + $requestMode = $askForUpdate ? 'ask' : 'enforce'; + $fieldSelector = sprintf('[name="%s"]', $parameterArray['itemFormElName']); + $resultArray['html'] .= '<typo3-formengine-updater mode="' . htmlspecialchars($requestMode) . '" field="' . htmlspecialchars($fieldSelector) . '"></typo3-formengine-updater>'; + } } return $resultArray; } -- GitLab