Check that 'replicate' link template exists before trying to use it

Created on 17 January 2023, over 1 year ago
Updated 24 March 2023, over 1 year ago

Problem/Motivation

Periodically our site will start throwing exceptions like

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'replicate' found for the 'node' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 196 of /mnt/www/html/docroot/core/lib/Drupal/Core/Entity/EntityBase.php

Even though nodes are definitely configured to use replicate. This is temporarily fixed with a cache rebuild but it always pops up again.

Looking around there is a similar issue from paragraphs https://www.drupal.org/project/paragraphs/issues/3238515#comment-14272727 πŸ’¬ No link template 'canonical' found for the 'paragraph' entity type Fixed that points to a usage of toUrl() without first calling hasLinkTemplate() and looking at replicate_ui there is indeed a usage of toUrl() without first checking the link template exists

https://git.drupalcode.org/project/replicate_ui/-/blob/8.x-1.x/replicate...

  if ($supports_replicate) {
    $url = $entity->toUrl('replicate');

    if ($url->access()) {

Proposed resolution

Add hasLinkTemplate('replicate') check before trying to use toUrl('replicate')

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ctrlADel North Carolina, USA

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.

Production build 0.69.0 2024