Problem/Motivation
The Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter
checks in its ::settingsForm
method on the entity type, whether it has a canonical link template. That is correct.
However, it also checks for canonical link template existence within ::viewElements
on the entity type. Since single entity instance are allowed to define whether they have a canonical link template on their own via EntityInterface::hasLinkTemplate
, the StringFormatter
should respect that accordingly.
Steps to reproduce
Proposed resolution
Replace the check on entity type level within StringFormatter::viewElements
by a check on the entity itself.
Meaning changing this line
if ($this->getSetting('link_to_entity') && !$entity->isNew() && $entity_type->hasLinkTemplate('canonical')) {
toif ($this->getSetting('link_to_entity') && !$entity->isNew() && $entity->hasLinkTemplate('canonical')) {