Skip to content

prevent an infinite loop when normalizing Link field value#18371

Merged
brandonkelly merged 4 commits into5.xfrom
bugfix/18363-link-field-and-custom-translation
Feb 3, 2026
Merged

prevent an infinite loop when normalizing Link field value#18371
brandonkelly merged 4 commits into5.xfrom
bugfix/18363-link-field-and-custom-translation

Conversation

@i-just
Copy link
Contributor

@i-just i-just commented Feb 3, 2026

Description

It’s possible to trigger an infinite loop when adding content to a Link field nested in a matrix field.

If you have a setup like the one described in the “steps to reproduce” section below, when you add a nested entry with a link field and fill in its content, we’ll try to normalise the Link field value. At this point, the nested entry is fresh, which means we're supposed to propagate its content.
To check whether we should localise a link to an element, we get the translation key for the element in the site we’re propagating to and from.
Because the translation method is set to custom and the translation key uses a template, we end up calling View::renderObjectTemplate().
Because the translation key template contains include(), we end up calling $object->toArray() using all the fields, and that will end up calling Link::normalizeValue(), which will try to get the translation key again, causing an infinite loop where the Link field value is never normalised.

It was introduced by this change: c3efaec.

Steps to reproduce:

  • clean 5.9.5 installation
  • create two sites, the primary one with the language set to en, and a second one with the language set to en-GB
  • create a template: gh18363-translation.twig with the following code in it: {{ object.site.language[0:2] }}
  • create a Link field (link18363) with all default settings and a translation method set to custom and translation key set to: {include('gh18363-translation.twig')}; (I also changed the order of the link types so that URL is first, as it makes it easier/quicker to test at the beginning)
  • create a Matrix field (matrix18363) with an entry type (withLink) that contains only the Link field from the previous step, propagation method set to custom, propagation key format set to {include('gh18363-translation.twig')} and view mode: blocks
  • create a section (gh18363) with all default settings (can have revisions, enabled for both sites, propagation: all, etc), with an entry type (et18363) that contains the Title field and the Matrix field from the previous step
  • create an entry in that section, fill out the title and fully save
  • edit the entry again, add a block to the matrix field, fill out the link field (e.g. type test.com) - watch the autosave spinner turn into the alert icon with an error mentioning an infinite loop

Additional notes:

  • the same will happen for a fresh entry if you click “New entry”, add a block to the matrix field and fill out the link field;
  • view mode doesn’t affect this; using the default cards view mode for the matrix field will yield the same results;

Temporary workaround:
Instead of using {include('gh18363-translation.twig')} as the translation key for the Link field, use the content of that template directly: {{object.site.language[0:2]}}.

Related issues

#18363

@i-just i-just requested a review from brandonkelly February 3, 2026 13:31
@brandonkelly brandonkelly merged commit 820955e into 5.x Feb 3, 2026
3 checks passed
@brandonkelly brandonkelly deleted the bugfix/18363-link-field-and-custom-translation branch February 3, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants