class EntityPagerLink in Entity Pager 8
Same name and namespace in other branches
- 2.0.x src/EntityPagerLink.php \Drupal\entity_pager\EntityPagerLink
A class representing a single Entity Pager link.
Hierarchy
- class \Drupal\entity_pager\EntityPagerLink implements EntityPagerLinkInterface uses StringTranslationTrait
Expanded class hierarchy of EntityPagerLink
1 file declares its use of EntityPagerLink
- EntityPagerLinkTest.php in tests/
src/ Kernel/ EntityPagerLinkTest.php
File
- src/
EntityPagerLink.php, line 12
Namespace
Drupal\entity_pagerView source
class EntityPagerLink implements EntityPagerLinkInterface {
use StringTranslationTrait;
/**
* The entity that this link is for.
*
* @var \Drupal\Core\Entity\EntityInterface|null
*/
public $entity;
/**
* The link text.
*
* @var string
*/
public $text;
/**
* Constructs an EntityPagerLink.
*
* @param string $text
* The text of the link.
* @param \Drupal\Core\Entity\EntityInterface|null $entity
* The result row in the view to link to.
*/
public function __construct($text, EntityInterface $entity = NULL) {
$this->text = $text;
$this->entity = $entity;
}
/**
* {@inheritdoc}
*/
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'),
];
}
/**
* Returns a render array for an entity pager link with no results.
*
* @return array
* The render array for the link with no results.
*/
protected function noResult() {
return [
'#type' => 'markup',
'#markup' => '<span class="inactive">' . $this->text . '</span>',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityPagerLink:: |
public | property | The entity that this link is for. | |
EntityPagerLink:: |
public | property | The link text. | |
EntityPagerLink:: |
public | function |
Returns a render array for the link. Overrides EntityPagerLinkInterface:: |
|
EntityPagerLink:: |
protected | function | Returns a render array for an entity pager link with no results. | |
EntityPagerLink:: |
public | function | Constructs an EntityPagerLink. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |