"Link label to the referenced entity" changed behavior from Drupal 10.1 to 10.2

Created on 19 January 2024, 10 months ago
Updated 14 March 2024, 8 months ago

Problem/Motivation

I had this issue https://www.drupal.org/project/workflow/issues/3415585 πŸ› Route "entity.workflow_state.canonical" does not exist Active .

A view containing a contrib workflow ( https://www.drupal.org/project/workflow β†’ ) "From state"/"To state" item worked in Drupal 10.1.x but broke in Drupal 10.2.x because of changed behaviour in views. Somehow those two elements had the option "Link label to the referenced entity" switched on, which should invoke the canonical view of them, but the elements never had a canonical view to start with. In Drupal 10.1.x this gets ignored, in Drupal 10.2.x it actually breaks the view.

Solution was to switch the option off to make it work. But more people will probably hit the problem, and it would be the nice if the option "Link label to the referenced entity" is not shown when the element in question does not have a canonical view (which should also automatically switch the option to off).

Steps to reproduce

Proposed resolution

#4. We could at least silently catch the exception in Views to avoid breaking things entirely.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 22 hours ago

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @sboden
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I think the change to default arguments to ::toUrl may have been the issue

    It broke aggregator module too

  • The problem is with a change in functionality of calling a canonical view when the "Link label to the referenced entity" is switched on. In Drupal 10.1.x when an element does not have a canonical view Drupal "skips" requesting it, while in Drupal 10.2.x you get a WSOD when the canonical view/route is called.

    For this I would propose not to show the "Link label to the referenced entity" for an element that does not have a canonical view. This would avoid Drupal calling something which does not exist. Example for this are the "From state"/"To state" fields from the contrib workflow module.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    We could at least silently catch the exception in Views to avoid breaking things entirely.

    Is there a core module that can be used to write a test for this?

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    This checkbox comes from \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter, Views just reuses the field formatter, so not sure if this is something Views should be handling or the FieldFormatter itself.

    @larowlan is πŸ“Œ Fall back to 'edit-form' as default $rel in EntityBase::toUrl() Fixed the change you are referring to? The formatter seems to catch the new exception thrown there so not sure.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Yeah that's the one that broke aggregator

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Just run into this with search_api_saved_searches and the SavedSearchType entity. Changing to a bug report, because this broke a view that worked in 10.1 but not in 10.2.

    The problem is that the entity declares the canonical and edit-form templates to be the same:

     *   links = {
     *     "canonical" = "/admin/config/search/search-api-saved-searches/type/{search_api_saved_search_type}/edit",
     *     "add-form" = "/admin/config/search/search-api-saved-searches/add-type",
     *     "edit-form" = "/admin/config/search/search-api-saved-searches/type/{search_api_saved_search_type}/edit",
    

    then this code makes an assumption about the route name:

        if (isset($link_templates[$rel])) {
          $route_parameters = $this->urlRouteParameters($rel);
          $route_name = "entity.{$this->entityTypeId}." . str_replace(['-', 'drupal:'], ['_', ''], $rel);
          $uri = new Url($route_name, $route_parameters);
        }
    

    However the entity.search_api_saved_search_type.canonical route does not actually exist - it shouldn't need to because the entity.search_api_saved_search_type.edit_form route does exist.

    Perhaps the whole block in EntityBase::toUrl() needs reworking to ensure that the route that it selects does actually exist; if the canonical route doesn't exist it could fall back to the edit-form route instead?

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
Production build 0.71.5 2024