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

Created on 24 October 2025, 11 days ago

Problem/Motivation

I get error Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 211 of core/lib/Drupal/Core/Entity/EntityBase.php). when add Mobile Native Share button to paragraph.

The problem caused by this line in mobile_native_share_entity_view():
$url = !empty($entity) ? $entity->toUrl('canonical', ['absolute' => TRUE])->toString() : NULL;
Not all entity types has 'canonical' url.

Proposed resolution

Wrap getting url in "try/catch". And if entity with Mobile Native Share button does not have 'canonical' url - use the current page URL, where this entity rendered.

    try {
      $url = $entity->toUrl('canonical', ['absolute' => TRUE])->toString();
    }
    catch (\Exception $e) {
      // If no link template 'canonical' found for the entity type,
      // set NULL to use the current page URL.
      $url = NULL;
    } 
🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

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.

No activities found.

Production build 0.71.5 2024