Skip to content

Commit

Permalink
[!!!][FEATURE] Move link resolving from field partial to hook
Browse files Browse the repository at this point in the history
This commit moves the whole link resolving to the corresponding hook.
As a side-effect, labels not making use of character substitution now
always get the resolved linked prepended to the label. This cannot be
changed unless character substitution is used to define the correct
link position.
  • Loading branch information
eliashaeussler committed Jan 12, 2022
1 parent 04ded37 commit d128090
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions Classes/Hooks/FormElementLinkResolverHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,23 @@ protected function processCharacterSubstitution(FormRuntime $formRuntime, RootRe
$this->formRuntime = $formRuntime;

// Only process linkText parsing if renderable matches given type
// and form element label contains any argument flags such as %s.
// This also checks if one tries to use the percent sign as regular
// character instead of a flag marked for inserting the translated
// linkText. It needs to be set as double-percent (%%) substring.
if (
!$renderable instanceof GenericFormElement ||
$renderable->getType() !== $this->type ||
!self::needsCharacterSubstitution($label = $this->translate($renderable, ['label']))
) {
if (!($renderable instanceof GenericFormElement) || $renderable->getType() !== $this->type) {
return;
}

$label = $this->translate($renderable, ['label']);
$properties = $renderable->getProperties();

// Check if form element label contains any argument flags such as %s.
// This also checks if one tries to use the percent sign as regular
// character instead of a flag marked for inserting the translated
// linkText. It needs to be set as double-percent (%%) substring.
// If character substitution is NOT requested, enforce the link to
// be prepended to the label text.
if (!self::needsCharacterSubstitution($label)) {
$label .= ' %s';
}

// Resolve all label arguments and merge them together in order to
// use it for later translation of the label. The following
// configuration methods are considered:
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Frontend/Partials/LinkedCheckbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
errorClass="{element.properties.elementErrorClassAttribute}"
additionalAttributes="{formvh:translateElementProperty(element: element, property: 'fluidAdditionalAttributes')}"
/>
<span>{formvh:translateElementProperty(element: element, property: 'label') -> f:format.raw()} <f:if condition="!{element.properties._linksProcessed}"><f:link.typolink parameter="{element.properties.pageUid}" target="_blank">{formvh:translateElementProperty(element: element, property: 'linkText')}</f:link.typolink></f:if><f:if condition="{element.required}"> <f:render partial="Field/Required" /></f:if></span>
<span>{formvh:translateElementProperty(element: element, property: 'label') -> f:format.stripTags(allowedTags: '<a>')}<f:if condition="{element.required}"><f:render partial="Field/Required" /></f:if></span>
</label>
</div>
</f:render>
Expand Down

0 comments on commit d128090

Please sign in to comment.