function 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 139

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\devel

Code

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