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
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
Comment #2
rupertj commentedComment #4
rupertj commentedComment #5
joachim commentedThe canonical link template is there because Drupal Code Builder generates it for config entities. I'll fix that too.
Comment #6
joachim commentedI'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:
Comment #7
rupertj commentedYup, 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?)
Comment #9
rupertj commentedIgnore that linked MR - I pushed to the wrong fork somehow.
Comment #11
rupertj commentedAnd 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
Comment #13
joachim commentedDevel still shows the tab without the link template, so all good.
Merged.