You are here

protected function LinkDelete::renderLink in File Entity (fieldable files) 8.2

Prepares the link to delete the media item.

Parameters

\Drupal\Core\Entity\EntityInterface $file: The file entity this field belongs to.

\Drupal\views\ResultRow $values: The values retrieved from the view's result set.

Return value

string|null Returns a string for the link text or returns null if user has no access.

File

src/Plugin/views/field/LinkDelete.php, line 30

Class

LinkDelete
Field handler to present a link to delete the file.

Namespace

Drupal\file_entity\Plugin\views\field

Code

protected function renderLink($file, ResultRow $values) {
  $text = NULL;

  // Ensure user has access to delete this media item.
  if ($file
    ->access('delete')) {
    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['path'] = 'file/' . $file
      ->id() . '/delete';
    $this->options['alter']['query'] = $this
      ->getDestinationArray();
    $text = !empty($this->options['text']) ? $this->options['text'] : t('Delete');
  }
  return $text;
}