You are here

public function EntityTypeInfo::entityOperation in Devel 8

Same name and namespace in other branches
  1. 8.3 src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityOperation()
  2. 8.2 src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityOperation()
  3. 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 82

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;
}