You are here

function role_delegation_entity_operation in Role Delegation 8

Implements hook_entity_operation().

File

./role_delegation.module, line 224
Allows admins to grant roles the authority to assign selected roles to users.

Code

function role_delegation_entity_operation(EntityInterface $entity) {
  $operations = [];
  if (!$entity instanceof UserInterface) {
    return $operations;
  }

  // Hide the entity operation when the current user has the 'administer users'
  // permission. Roles can be edited on the user edit page.
  if (!\Drupal::currentUser()
    ->hasPermission('administer users')) {
    return;
  }
  $url = Url::fromRoute('role_delegation.edit_form', [
    'user' => $entity
      ->id(),
  ]);

  // Check if the current user has access to the role_delegation edit form.
  if ($url
    ->access()) {
    $operations['role_delegation'] = [
      'title' => t('Roles'),
      'weight' => 210,
      'url' => $url,
    ];
  }
  return $operations;
}