function EntityTypeInfo::entityOperation

Same name in other branches
  1. 8.x-1.x src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityOperation()
  2. 4.x src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityOperation()

Adds devel operations on entity that supports it.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which to define an operation.

Return value

array An array of operation definitions.

See also

hook_entity_operation()

File

src/EntityTypeInfo.php, line 138

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\devel

Code

public function entityOperation(EntityInterface $entity) : array {
    $operations = $parameters = [];
    if ($this->currentUser
        ->hasPermission('access devel information')) {
        if ($entity->hasLinkTemplate('canonical')) {
            $parameters = $entity->toUrl('canonical')
                ->getRouteParameters();
        }
        if ($entity->hasLinkTemplate('devel-load')) {
            $url = $entity->toUrl('devel-load');
            $operations['devel'] = [
                'title' => $this->t('Devel'),
                'weight' => 100,
                'url' => $parameters ? $url->setRouteParameters($parameters) : $url,
            ];
        }
        elseif ($entity->hasLinkTemplate('devel-render')) {
            $url = $entity->toUrl('devel-render');
            $operations['devel'] = [
                'title' => $this->t('Devel'),
                'weight' => 100,
                'url' => $parameters ? $url->setRouteParameters($parameters) : $url,
            ];
        }
    }
    return $operations;
}