[regression] toUrl can incorrectly return edit-form url when another link template shares the canonical url

Created on 20 December 2023, almost 2 years ago
Updated 5 March 2024, over 1 year ago

Problem/Motivation

After upgrading to Drupal 10.2, one of our tests was failing that asserted that visiting the canonical route of an entity returned the latest revision. That's because we have the following link templates in the entity definition

...
 *     "canonical" = "/admin/content/location/{location}",
 *     "latest-version" = "/admin/content/location/{location}",
...

This worked perfectly fine in 10.1. However, since πŸ“Œ Fall back to 'edit-form' as default $rel in EntityBase::toUrl() Fixed this behaviour has changed. Most importantly, the issue is with the array_flip. Link templates don't have to have unique url patterns, flipping the above example deletes the canonical route because of the duplicate keys, therefore the new fallback logic in EntityBase::toUrl uses the edit-form link template.

Steps to reproduce

Install Drupal 10.2
Create an entity type with 2 link templates with the same url template and an edit-form template
Call toUrl with no parameters
Notice you get the edit-form url, not the canonical one.

Proposed resolution

Dont use array_flip

Remaining tasks

Code
Test
Review

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡¦πŸ‡ΊAustralia acbramley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024