You are here

protected function EntityViewsData::addEntityLinks in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/EntityViewsData.php \Drupal\views\EntityViewsData::addEntityLinks()
  2. 9 core/modules/views/src/EntityViewsData.php \Drupal\views\EntityViewsData::addEntityLinks()

Sets the entity links in case corresponding link templates exist.

Parameters

array $data: The views data of the base table.

File

core/modules/views/src/EntityViewsData.php, line 389

Class

EntityViewsData
Provides generic views integration for entities.

Namespace

Drupal\views

Code

protected function addEntityLinks(array &$data) {
  $entity_type_id = $this->entityType
    ->id();
  $t_arguments = [
    '@entity_type_label' => $this->entityType
      ->getLabel(),
  ];
  if ($this->entityType
    ->hasLinkTemplate('canonical')) {
    $data['view_' . $entity_type_id] = [
      'field' => [
        'title' => $this
          ->t('Link to @entity_type_label', $t_arguments),
        'help' => $this
          ->t('Provide a view link to the @entity_type_label.', $t_arguments),
        'id' => 'entity_link',
      ],
    ];
  }
  if ($this->entityType
    ->hasLinkTemplate('edit-form')) {
    $data['edit_' . $entity_type_id] = [
      'field' => [
        'title' => $this
          ->t('Link to edit @entity_type_label', $t_arguments),
        'help' => $this
          ->t('Provide an edit link to the @entity_type_label.', $t_arguments),
        'id' => 'entity_link_edit',
      ],
    ];
  }
  if ($this->entityType
    ->hasLinkTemplate('delete-form')) {
    $data['delete_' . $entity_type_id] = [
      'field' => [
        'title' => $this
          ->t('Link to delete @entity_type_label', $t_arguments),
        'help' => $this
          ->t('Provide a delete link to the @entity_type_label.', $t_arguments),
        'id' => 'entity_link_delete',
      ],
    ];
  }
}