You are here

protected function ListUsageController::getSourceEntityCanonicalLink in Entity Usage 8.3

Retrieve a link to the source entity on its canonical page.

Parameters

\Drupal\Core\Entity\EntityInterface $source_entity: The source entity.

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.

1 call to ListUsageController::getSourceEntityCanonicalLink()
ListUsageController::listUsagePage in src/Controller/ListUsageController.php
Lists the usage of a given entity.

File

src/Controller/ListUsageController.php, line 306

Class

ListUsageController
Controller for our pages.

Namespace

Drupal\entity_usage\Controller

Code

protected function getSourceEntityCanonicalLink(EntityInterface $source_entity, $text = NULL) {
  $entity_label = $source_entity
    ->access('view label') ? $source_entity
    ->label() : $this
    ->t('- Restricted access -');

  // Prevent 404s by exposing the label unlinked if the user has no access
  // to view the entity.
  if ($source_entity
    ->hasLinkTemplate('canonical') && $source_entity
    ->access('view')) {
    return $source_entity
      ->toLink();
  }
  else {
    return $entity_label;
  }
}