You are here

public function FileManagementOperations::render in File Management 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides EntityOperations::render

File

src/Plugin/views/field/FileManagementOperations.php, line 21

Class

FileManagementOperations
Renders all operations links for a file.

Namespace

Drupal\file_management\Plugin\views\field

Code

public function render(ResultRow $values) {
  $entity = $this
    ->getEntityTranslation($this
    ->getEntity($values), $values);
  $operations = [
    'edit' => [
      'title' => $this
        ->t('Edit'),
      'url' => Url::fromRoute('file_management.edit_page', [
        'file' => $entity
          ->id(),
      ]),
      'weight' => 1,
    ],
    'view' => [
      'title' => $this
        ->t('View'),
      'url' => Url::fromRoute('file_management.view_page', [
        'file' => $entity
          ->id(),
      ]),
      'weight' => 2,
    ],
    'delete' => [
      'title' => $this
        ->t('Delete'),
      'url' => Url::fromRoute('file_management.delete_page', [
        'file' => $entity
          ->id(),
      ]),
      'weight' => 3,
    ],
  ];
  if ($this->options['destination']) {
    foreach ($operations as &$operation) {
      if (!isset($operation['query'])) {
        $operation['query'] = [];
      }
      $operation['query'] += $this
        ->getDestinationArray();
    }
  }
  $build = [
    '#type' => 'operations',
    '#links' => $operations,
  ];
  return $build;
}