Canonical and shortlink of snippet pages are under admin path/route

Created on 7 August 2025, 22 days ago

Problem/Motivation

Snippet page has unvaluable html_head_link, which are: canonical and shortlink of "/admin/structure/snippet/{snippet}"

The issue cause because of the Drupal\snippet_manager\EventSubscriber\RouteSubscriber::buildRoute given the _entity_view: 'snippet.full'. Therefore, EntityRouteEnhancer::enhanceEntityView() automatically add $defaults['_controller'] = '\Drupal\Core\Entity\Controller\EntityViewController::view';

And result are:
1. The controller found the snippet hasLinkTemplate of canonical
2. the EntityViewController add the html_head_link within the canonical link.
3. The shared Snippet page on other social network can not get the preview (got access denied)

Proposed resolution

1. Create new SnippetViewController extend EntityViewController.
2. Update the RouteSubscriber::builtRoute()` to add `$defaults['_controller'] = SnippetViewController;
3. in SnippetViewController::view(), update the canonical, shortlink href by getting snippet page path.
4. Dispatch hook_snippet_view_controller_alter for alter the $page result in SnippetViewController::view().

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇻🇳Vietnam mrddthi

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