Canonical link is declared but not defined

Created on 30 January 2024, 8 months ago
Updated 9 February 2024, 8 months ago

Problem/Motivation

Canonical link for simple block entity is declared in class SimpleBlock annotation:

 *     "canonical" = "/admin/structure/block/simple-block/manage/{simple_block}",

but route is not defined anywhere in module.
This could lead to errors if other modules make use of method toUrl() of a simple block entity.
For example, this code taken from responsive theme preview ( https://www.drupal.org/project/responsive_preview )

...
if ($entity->hasLinkTemplate('canonical')) {
    return $entity->toUrl()->toString();
}
...

while condition is always TRUE for simple block entities, $entity->toUrl() returns this error:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.simple_block.canonical" does not exist

Proposed resolution

Simply remove canonical link in entity annotation.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇹Italy maurizio.ganovelli Arezzo

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