class EntityLink
Same name in this branch
- 9 core/modules/comment/src/Plugin/views/field/EntityLink.php \Drupal\comment\Plugin\views\field\EntityLink
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/field/EntityLink.php \Drupal\views\Plugin\views\field\EntityLink
- 11.x core/modules/comment/src/Plugin/views/field/EntityLink.php \Drupal\comment\Plugin\views\field\EntityLink
- 10 core/modules/views/src/Plugin/views/field/EntityLink.php \Drupal\views\Plugin\views\field\EntityLink
- 10 core/modules/comment/src/Plugin/views/field/EntityLink.php \Drupal\comment\Plugin\views\field\EntityLink
- 8.9.x core/modules/views/src/Plugin/views/field/EntityLink.php \Drupal\views\Plugin\views\field\EntityLink
- 8.9.x core/modules/comment/src/Plugin/views/field/EntityLink.php \Drupal\comment\Plugin\views\field\EntityLink
Field handler to present a link to an entity.
Plugin annotation
@ViewsField("entity_link");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\LinkBase uses \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\views\Entity\Render\EntityTranslationRenderTrait extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\EntityLink extends \Drupal\views\Plugin\views\field\LinkBase
- class \Drupal\views\Plugin\views\field\LinkBase uses \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\views\Entity\Render\EntityTranslationRenderTrait extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of EntityLink
Related topics
1 file declares its use of EntityLink
- TranslationLink.php in core/
modules/ content_translation/ src/ Plugin/ views/ field/ TranslationLink.php
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ EntityLink.php, line 15
Namespace
Drupal\views\Plugin\views\fieldView source
class EntityLink extends LinkBase {
/**
* {@inheritdoc}
*/
public function render(ResultRow $row) {
return $this->getEntity($row) ? parent::render($row) : [];
}
/**
* {@inheritdoc}
*/
protected function renderLink(ResultRow $row) {
if ($this->options['output_url_as_text']) {
return $this->getUrlInfo($row)
->toString();
}
return parent::renderLink($row);
}
/**
* {@inheritdoc}
*/
protected function getUrlInfo(ResultRow $row) {
$template = $this->getEntityLinkTemplate();
$entity = $this->getEntity($row);
if ($this->languageManager
->isMultilingual()) {
$entity = $this->getEntityTranslation($entity, $row);
}
return $entity->toUrl($template)
->setAbsolute($this->options['absolute']);
}
/**
* Returns the entity link template name identifying the link route.
*
* @returns string
* The link template name.
*/
protected function getEntityLinkTemplate() {
return 'canonical';
}
/**
* {@inheritdoc}
*/
protected function getDefaultLabel() {
return $this->t('view');
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['output_url_as_text'] = [
'default' => FALSE,
];
$options['absolute'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['output_url_as_text'] = [
'#type' => 'checkbox',
'#title' => $this->t('Output the URL as text'),
'#default_value' => $this->options['output_url_as_text'],
];
$form['absolute'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use absolute link (begins with "http://")'),
'#default_value' => $this->options['absolute'],
'#description' => $this->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination.'),
];
parent::buildOptionsForm($form, $form_state);
// Only show the 'text' field if we don't want to output the raw URL.
$form['text']['#states']['visible'][':input[name="options[output_url_as_text]"]'] = [
'checked' => FALSE,
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.