custom_breadcrumbs_entity_extra_field_info() adds a "Breadcrumbs" extra field to every bundle of every entity type. This includes entity types that have no canonical URL, such as Paragraphs.
If that field is enabled on such an entity's display, custom_breadcrumbs_entity_view() calls $entity->toUrl(), which throws:
Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the 'paragraph' entity type in Drupal\Core\Entity\EntityBase->toUrl() (line 211 of core/lib/Drupal/Core/Entity/EntityBase.php).
Backtrace (top):
#0 modules/contrib/custom_breadcrumbs/custom_breadcrumbs.module(68): Drupal\Core\Entity\EntityBase->toUrl()
#1 [internal function]: custom_breadcrumbs_entity_view(Array, Object(Drupal\paragraphs\Entity\Paragraph), Object(Drupal\Core\Entity\Entity\EntityViewDisplay), 'default')The error occurs wherever the paragraph is rendered: node pages, Views output and Views UI preview.
Steps to reproduce
- Install Custom breadcrumbs 1.1.3 and Paragraphs.
- Create a paragraph type. In Manage display, move Breadcrumbs from Disabled to an enabled region and save.
- Add a Paragraphs field using that type to a content type.
- Create a node with a paragraph of that type and view it.
- The exception is logged.
Environment: Drupal core [version], PHP [version].
Proposed resolution
- In custom_breadcrumbs_entity_extra_field_info(), skip entity types without a canonical link template, so the field isn't offered where it can't work.
- In custom_breadcrumbs_entity_view(), add a defensive check before calling toUrl(), for sites that already have the component enabled on such displays.
--- a/custom_breadcrumbs.module
+++ b/custom_breadcrumbs.module
@@ -47,6 +47,9 @@ function custom_breadcrumbs_entity_extra_field_info() {
$entityBundleInfo = \Drupal::service('entity_type.bundle.info');
foreach ($entity_types as $key => $type) {
+ if (!$type->hasLinkTemplate('canonical')) {
+ continue;
+ }
foreach ($entityBundleInfo->getBundleInfo($key) as $bundle_key => $bundle_name) {
$extra[$key][$bundle_key]['display']['breadcrumbs'] = [
'label' => t('Breadcrumbs'),
@@ -64,7 +67,7 @@ function custom_breadcrumbs_entity_extra_field_info() {
* Implements hook_entity_view().
*/
function custom_breadcrumbs_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
- if ($display->getComponent('breadcrumbs')) {
+ if ($display->getComponent('breadcrumbs') && $entity->hasLinkTemplate('canonical')) {
$url = $entity->toUrl();
$router = \Drupal::service('router.no_access_checks');
$result = $router->match($url->toString());Workaround: Disable the Breadcrumbs field in Manage display for the affected paragraph type.
Comments