- Issue created by @jwilson3
- Merge request !9Issue #3500376 by jwilson3: Support entity types that don't have link templates (like Paragraphs) → (Open) created by jwilson3
When the parent entity containing a field using Element Class Formatter does NOT implement the toUrl()
a WSOD is displayed and internally a PHP Exception is thrown. Paragraphs do not implement toUrl() because they don't contain a canonical link URL.
TypeError: Drupal\Core\Link::fromTextAndUrl(): Argument #2 ($url) must be of type Drupal\Core\Url, string given, called in modules/contrib/element_class_formatter/src/Plugin/Field/FieldFormatter/WrapperClassFormatter.php on line 215 in Drupal\Core\Link::fromTextAndUrl() (line 93 of core/lib/Drupal/Core/Link.php).
Drupal\element_class_formatter\Plugin\Field\FieldFormatter\WrapperClassFormatter->viewElements(Object, 'en') (Line: 91)
Related generic error message:
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).
Check whether the parent entity will cause a WSOD when calling ->toUrl()
before calling the method. This can be confirmed via $entity->hasLinkTemplate('canonical')
. See
#3238515-14: No link template 'canonical' found for the 'paragraph' entity type →
for additional context.
Active
2.1
Code