No link template 'canonical' found for the 'paragraph' entity type

Created on 22 September 2021, over 3 years ago
Updated 27 February 2023, about 2 years ago

Problem/Motivation

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of core/lib/Drupal/Core/Entity/EntityBase.php).

Steps to reproduce

Get Drupal 9 and paste this code in the first hook_page_attachments_alter you find.

\Drupal::entityTypeManager()->getStorage('paragraph')->load(1)->toUrl();

Proposed resolution

Extend the base function toUrl and add a try catch.

Remaining tasks

Apply patch and see if that works.

๐Ÿ’ฌ Support request
Status

Fixed

Version

1.14

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Kumar Rakesh

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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States JCL324 Portland, OR

    Just got this too with Drupal 10 core, Paragraphs 8.x-1.15:

    Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of core/lib/Drupal/Core/Entity/EntityBase.php).

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smethawee

    I just got this too when I updated from Drupal 9.5.2 to Drupal 9.5.4 core, Paragraphs 8.x-1.15:

    The website encountered an unexpected error. Please try again later.

    Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of core/lib/Drupal/Core/Entity/EntityBase.php).

    How to solve this issue? I still got this.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Greg Boggs Portland Oregon

    This patch works for us in D9.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    See #20 for example. You fix this error enabling verbose errors with backtrace, see who is incorrectly calling toUrl() on an entity without checking if it has a canonical link template. It might be comments, there is an issue referenced above, or another contrib or custom module.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    I'm seeing this on Paragraphs 1.15.

    The site is a build with no custom code touching this area. The error is resolved with the rerolled patch at #17 is working for me. @akhilavnair, the only tweak I'd suggest is code standards on the comment.

    Given there are many reports of this being resolved by fixing it in Paragraphs I'm unsure why this isn't just being resolved here.

    It works. Using the patch at #17 with cwegans/composer-patches for now.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Dishvola

    In my case I need a view of the all webform submissions with a links to source entity and it's a paragraph for some cases... so the system can't to get it and I see a whitescreen.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom freelylw

    got this problem again in my drupal 9, after upgrade the core to 10, the problem stay exist

    https://www.drupal.org/project/paragraphs/issues/3404000 ๐Ÿ› The website encountered an unexpected error. ( problem with layout builder ) Active

  • First commit to issue fork.
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Liam Morland โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Success
    8 months ago
    Total: 437s
    #248161
  • Pipeline finished with Failed
    8 months ago
    Total: 473s
    #248160
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States andysipple

    #17 was no longer applying for me.
    Reroll #17

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    Rerolled patch at #35 applies and still works as expected.

    Cheers @andysipple.

  • ๐Ÿ‡ช๐Ÿ‡จEcuador jwilson3

    Patch in #35 did not work for my case, so I've followed the directions in #14 and filed an issue in the contrib module I'm using to better support Paragraphs by testing whether entities implement a canonical link template before calling toUrl()

    ๐Ÿ“Œ Support entity types that don't have link templates (like Paragraphs) Active

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States socketwench

    I was able to replicate this using paragraphs and core alone.

    In our case, we had an image field on a paragraph. The image field was configured to link to content. In `core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php`, that resolves to:

        if ($image_link_setting == 'content') {
          $entity = $items->getEntity();
          if (!$entity->isNew()) {
            $url = $entity->toUrl();

    Since the paragraph is the parent entity in this case, core gets the paragraph, then attempts to generate the default link template, causing the error.

    Removing the link to content resolves the error, but this is a workaround. The proper solution is that either core has to cross check that the default link template is available, or Paragraphs needs to provide it in all cases, even if it links to nothing.

  • ๐Ÿ‡ช๐Ÿ‡จEcuador jwilson3

    Since Paragraphs ultimately have to be "attached" to some entity, perhaps there is a way that the canonical link implementation could dynamically recurse up the entity reference tree using Paragraphs::getParentEntity() until it finds the first parent entity that has a canonical link and return that?

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine sanyok_medved

    This issue is reproduced when I have Paragraph as Reference inside Paragraph. It looks up for. parent link "canonical" but paragraph doesn't have canonical. I've attached patch for this. It is in ImageFormatter field. When you use Image in Paragraph and have link to parent.

  • ๐Ÿ‡ช๐Ÿ‡จEcuador jwilson3

    Since the patch in Comment #40 is for Drupal core, I suggest creating a Drupal core issue if for no other reason than to see what core maintainers have to say about this issue.

Production build 0.71.5 2024