Cover any canonical route

Created on 15 October 2024, 2 months ago

Problem/Motivation

Currently, the alterUrl() method of the RabbitHoleLinksLinkGenerator is only processed for node canonical urls. Therefore, eg. a link to taxonomy term won't be captured.

Proposed resolution

Remove the route name check and, eg. check the given $url against the $url's entity canonical url, like this:
$entity->toUrl('canoncial') == $url

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany drupatz

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

Merge Requests

Comments & Activities

  • Issue created by @drupatz
  • Merge request !23480690 change check logic → (Merged) created by drupatz
  • Pipeline finished with Skipped
    2 months ago
    #310946
  • First commit to issue fork.
  • 🇩🇪Germany Hydra

    We should do that, thx.

  • 🇩🇪Germany drupatz

    The fix is insufficient, causing a fatal error at eg. /admin/config/search/path:

    The website encountered an unexpected error. Try again later.
    
    Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'path_alias' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 211 of core/lib/Drupal/Core/Entity/EntityBase.php).
    Drupal\rabbit_hole_links\RabbitHoleLinksLinkGenerator->alterUrl(Object) (Line: 39)
    Drupal\rabbit_hole_links\RabbitHoleLinksLinkGenerator->generate(Object, Object) (Line: 102)
    Drupal\Core\Render\Element\Link::preRenderLink(Array)
    call_user_func_array(Array, Array) (Line: 113)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array) (Line: 475)
    Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 102)
    __TwigTemplate_e441fd9091f1d74a88b0682501a7d286->doDisplay(Array, Array) (Line: 393)
    Twig\Template->yield(Array, Array) (Line: 349)
    Twig\Template->display(Array) (Line: 364)
    Twig\Template->render(Array) (Line: 35)
    Twig\TemplateWrapper->render(Array) (Line: 33)
    twig_render_template('themes/contrib/gin/templates/form/links--dropbutton.html.twig', Array) (Line: 348)
    Drupal\Core\Theme\ThemeManager->render('links__dropbutton', Array) (Line: 491)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array) (Line: 475)
    Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 186)
    __TwigTemplate_60de49ce76b2b1890b1c0b7c949f6472->doDisplay(Array, Array) (Line: 393)
    Twig\Template->yield(Array, Array) (Line: 349)
    Twig\Template->display(Array) (Line: 364)
    Twig\Template->render(Array) (Line: 35)
    Twig\TemplateWrapper->render(Array) (Line: 33)
    twig_render_template('themes/contrib/gin/templates/dataset/table.html.twig', Array) (Line: 348)
    Drupal\Core\Theme\ThemeManager->render('table', Array) (Line: 491)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 77)
    Drupal\lnx_base\HeadersMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
    Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • Merge request !3Resolve #3480690 "Cover any canonical" → (Closed) created by drupatz
  • Merge request !4Resolve #3480690 "Cover any canonical bugfix" → (Closed) created by drupatz
  • Merge request !5Resolve #3480690 "Cover any canonical bug" → (Closed) created by drupatz
  • 🇩🇪Germany Hydra

    This has been fixed in https://www.drupal.org/project/rabbit_hole_links/issues/3481374 🐛 Fatal at /admin/config/search/path Active

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

Production build 0.71.5 2024