Skip to content

Commit

Permalink
[!!!][BUGFIX] Switch EXT:form hook to respect applied variants
Browse files Browse the repository at this point in the history
The previously used hook `afterFormStateInitialized` is executed before
variants are applied in `FormRuntime`. This could lead to an
inconsistent state of LinkedCheckbox elements in case variants are
configured.

To circumvent this behavior, the hook `afterInitializeCurrentPage` is
now used instead.

This change is considered breaking as references to the previously
configured hook will no longer work.
  • Loading branch information
eliashaeussler committed Nov 30, 2022
1 parent a28dc11 commit 543830b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Classes/Configuration/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public static function addTypoScriptSetup(): void

public static function registerHooks(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterFormStateInitialized'][1571076908] = FormElementLinkResolverHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterInitializeCurrentPage'][1571076908] = FormElementLinkResolverHook::class;
}
}
12 changes: 6 additions & 6 deletions Classes/Hooks/FormElementLinkResolverHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement;
use TYPO3\CMS\Form\Domain\Model\FormElements\Page;
use TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime\Lifecycle\AfterFormStateInitializedInterface;
use TYPO3\CMS\Form\Service\TranslationService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

Expand All @@ -33,7 +33,7 @@
* @license GPL-2.0-or-later
* @internal
*/
final class FormElementLinkResolverHook implements AfterFormStateInitializedInterface
final class FormElementLinkResolverHook
{
/**
* @var string Form element type to match
Expand All @@ -47,16 +47,16 @@ final class FormElementLinkResolverHook implements AfterFormStateInitializedInte

/**
* Resolve link in label of form elements with type LinkedCheckbox.
*
* @param FormRuntime $formRuntime
*/
public function afterFormStateInitialized(FormRuntime $formRuntime): void
public function afterInitializeCurrentPage(FormRuntime $formRuntime, ?Page $currentPage): ?Page
{
$renderables = $formRuntime->getFormDefinition()->getRenderablesRecursively();

foreach ($renderables as $renderable) {
$this->processCharacterSubstitution($formRuntime, $renderable);
}

return $currentPage;
}

/**
Expand Down Expand Up @@ -205,7 +205,7 @@ private function hasAdditionalLinksConfigured(GenericFormElement $element): bool
{
$properties = $element->getProperties();

return is_array($properties['additionalLinks'] ?? null) && [] !== $properties['additionalLinks'];
return is_array($properties['additionalLinks'] ?? null) && $properties['additionalLinks'] !== [];
}

/**
Expand Down

0 comments on commit 543830b

Please sign in to comment.