You are here

public function SearchApiEntityOperations::render in Search API 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/SearchApiEntityOperations.php, line 26

Class

SearchApiEntityOperations
Renders all operations links for an entity.

Namespace

Drupal\search_api\Plugin\views\field

Code

public function render(ResultRow $values) {
  $build = [];
  try {
    $entity = $this
      ->getContainedEntity($values->_item
      ->getOriginalObject());
  } catch (SearchApiException $e) {
    $this
      ->logException($e);
    return $build;
  }
  if ($entity) {
    $entity_type = $entity
      ->getEntityType();
    if ($entity_type
      ->hasListBuilderClass()) {
      $operations = $this->entityTypeManager
        ->getListBuilder($entity_type
        ->id())
        ->getOperations($entity);
      if ($this->options['destination']) {
        foreach ($operations as $i => $operation) {
          if (!isset($operation['query'])) {
            $operation['query'] = [];
          }
          $operation['query'] += $this
            ->getDestinationArray();
          $operations[$i] = $operation;
        }
      }
      $build = [
        '#type' => 'operations',
        '#links' => $operations,
        '#cache' => [
          'contexts' => [
            'url',
          ],
        ],
      ];
    }
  }
  return $build;
}