You are here

function duplicate_role_entity_operation in Duplicate role 8

Implements hook_entity_operation().

File

./duplicate_role.module, line 14
Provides functionality for duplicating roles.

Code

function duplicate_role_entity_operation(EntityInterface $entity) {
  $operations = [];
  if ($entity
    ->getEntityTypeId() === 'user_role' && \Drupal::currentUser()
    ->hasPermission('administer duplicate role')) {
    $operations['duplicate'] = [
      'title' => t('Duplicate'),
      'url' => Url::fromRoute('duplicaterole.overview', [
        'role' => $entity
          ->id(),
      ]),
      'weight' => 20,
    ];
  }
  return $operations;
}