Skip to content

[5.x]: Incorrect Link field URLs after assigning a new website to a section #17072

@nikolenko-dmitriy

Description

@nikolenko-dmitriy

What happened?

Description

When adding a new site to an existing section, entries are correctly cloned from the primary site - that's expected and works well.

However, if the original entries from the primary site contain a Link field with the Entry type selected, the resulting link in the new site's cloned entry still points to the original entry URL on the primary site.

I guess this happens because the link field stores the site ID as part of its value, in a format like {entry:1321@1:url}, where 1 refers to the ID of the primary site.

When entries are duplicated for the new site, this internal reference remains unchanged, leading to incorrect URLs.

Steps to reproduce

  1. Create two websites with different languages and base URLs:
    • NL: localhost/nl (set as the primary site)
    • FR: localhost/fr
  2. Create a section called Pages and assign both websites to it.
  3. Create a Link field, make it translatable, and assign it to the Pages section.
  4. Add entries in the Pages section: e.g., Home and Contact.
  5. In the Home entry, set the Link field to type Entry, and select the Contact entry.
  6. On the entry detail template, display the link field value.
  7. Confirm that the link on the NL and FR Home entries correctly points to the local Contact page.
  8. Now, create a new website:
    • EN: localhost/en
  9. Assign the EN site to the Pages section.
  10. New entries are created for the EN site, but the link in the Home entry still points to the NL Contact page (localhost/nl/contact).

Expected behavior

When assigning the new EN site to the Pages section, the Link field in the Home entry should point to the EN version of the Contact page:

localhost/en/contact

Actual behavior

The Link field in the Home entry for the EN site still points to the NL version of the Contact page:

localhost/nl/contact

Craft CMS version

5.5.3

PHP version

8.2.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions