function EntityOperations::render

Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations::render()
  2. 10 core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations::render()
  3. 11.x core/modules/views/src/Plugin/views/field/EntityOperations.php \Drupal\views\Plugin\views\field\EntityOperations::render()

Overrides FieldPluginBase::render

File

core/modules/views/src/Plugin/views/field/EntityOperations.php, line 129

Class

EntityOperations
Renders all operations links for an entity.

Namespace

Drupal\views\Plugin\views\field

Code

public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    // Allow for the case where there is no entity, if we are on a non-required
    // relationship.
    if (empty($entity)) {
        return '';
    }
    $entity = $this->getEntityTranslation($entity, $values);
    $operations = $this->entityTypeManager
        ->getListBuilder($entity->getEntityTypeId())
        ->getOperations($entity);
    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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.