private function ListUsageController::getReferencingEntityLink in Entity Usage 8
Retrieve a link to the referencing entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $referencing_entity: The fully-loaded referencing entity.
string|null $text: (optional) The link text for the anchor tag as a translated string. If NULL, it will use the entity's label. Defaults to NULL.
Return value
\Drupal\Core\Link|string A link to the entity, or its non-linked label, in case it was impossible to correctly build a link. Note that Paragraph entities are specially treated. This function will return the link to its parent entity, relying on the fact that paragraphs have only one single parent and don't have canonical template.
1 call to ListUsageController::getReferencingEntityLink()
- ListUsageController::listUsagePage in src/
Controller/ ListUsageController.php - Lists the usage of a given entity.
File
- src/
Controller/ ListUsageController.php, line 158
Class
- ListUsageController
- Controller for our pages.
Namespace
Drupal\entity_usage\ControllerCode
private function getReferencingEntityLink(ContentEntityInterface $referencing_entity, $text = NULL) {
$entity_label = $referencing_entity
->access('view label') ? $referencing_entity
->label() : $this
->t('- Restricted access -');
if ($referencing_entity
->hasLinkTemplate('canonical')) {
$link_text = $text ?: $entity_label;
// Prevent 404s by exposing the text unlinked if the user has no access
// to view the entity.
return $referencing_entity
->access('view') ? $referencing_entity
->toLink($link_text) : $link_text;
}
// Treat paragraph entities in a special manner. Once the current paragraphs
// implementation does not support reusing paragraphs, it is safe to
// consider that each paragraph entity is attached to only one parent
// entity. For this reason we will use the link to the parent's entity,
// adding a note that the parent uses this entity through a paragraph.
// @see #2414865 and related issues for more info.
if ($referencing_entity
->getEntityTypeId() == 'paragraph' && ($parent = $referencing_entity
->getParentEntity())) {
return $this
->getReferencingEntityLink($parent, $entity_label);
}
// As a fallback just return a non-linked label.
return $entity_label;
}