When editing a finder entity, with the responsive_preview module installed, I get an exception thrown:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.finder.canonical" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 208 of core/lib/Drupal/Core/Routing/RouteProvider.php).

This is triggered by these lines in responsive_preview:

if ($entity->hasLinkTemplate('canonical')) {
  return $entity->toUrl()->toString();
}

The cause is that the Finder entity declares a canonical link, but doesn't declare a view_builder handler. The lack of view_builder causes \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCanonicalRoute() to not add the canonical route to the routing, and hence we get the exception thrown.

Taking out the canonical link template from the entity annotation fixes this.

Issue fork finders-3498926

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rupertj created an issue. See original summary.

rupertj’s picture

Issue summary: View changes

rupertj’s picture

Status: Active » Needs review
joachim’s picture

The canonical link template is there because Drupal Code Builder generates it for config entities. I'll fix that too.

joachim’s picture

I've got a feeling I added this in DCB so that Devel module gives us a devel tab on Finder entities.

Core doesn't expect that a canonical route necessarily means there's a view builder -- in DefaultHtmlRouteProvider:

    if ($entity_type->hasLinkTemplate('canonical') && $entity_type->hasViewBuilderClass()) {
rupertj’s picture

Yup, and that's the code that causes the problem by going on to not create the routing for the canonical link.

If you look through EntityBase::toUrl(), that checks to see if there's a canonical link template. If there is, it uses the (missing) route. If there isn't a canonical link template, it falls back to the edit-form link template. I think this behaviour is what we want to happen.

I feel like the pragmatic fix here is to take out canonical from the Finder entity, but there's arguably something that should be done better in core. (Maybe adding Drupal\Core\Entity\EntityViewBuilder as the view_builder for entities that declare a canonical route template and no view_builder?)

rupertj’s picture

Ignore that linked MR - I pushed to the wrong fork somehow.

rupertj’s picture

And I've fixed up the original PR which somehow ended up with the other commit in it. (It's still listed on the activity page, but it's not in the changes): https://git.drupalcode.org/project/finders/-/merge_requests/1

  • joachim committed 2590250c on 1.0.x authored by rupertj
    Issue #3498926: Removed canonical link template for finder entity type.
    
joachim’s picture

Status: Needs review » Fixed

Devel still shows the tab without the link template, so all good.

Merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.