You are here

public function EntityPagerLink::getLink in Entity Pager 8

Same name and namespace in other branches
  1. 2.0.x src/EntityPagerLink.php \Drupal\entity_pager\EntityPagerLink::getLink()

Returns a render array for the link.

Return value

array A render array for the link

Overrides EntityPagerLinkInterface::getLink

File

src/EntityPagerLink.php, line 46

Class

EntityPagerLink
A class representing a single Entity Pager link.

Namespace

Drupal\entity_pager

Code

public function getLink() {
  if (empty($this->entity)) {
    return $this
      ->noResult();
  }
  $langcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $entity = $this->entity;
  if ($entity instanceof TranslatableInterface && $entity
    ->hasTranslation($langcode)) {
    $entity = $entity
      ->getTranslation($langcode);
  }
  return [
    '#type' => 'link',
    '#title' => [
      '#markup' => $this->text,
    ],
    '#url' => $entity
      ->toUrl('canonical'),
  ];
}