You are here

duplicate_role.module in Duplicate role 8

Provides functionality for duplicating roles.

File

duplicate_role.module
View source
<?php

/**
 * @file
 * Provides functionality for duplicating roles.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
 * Implements hook_entity_operation().
 */
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;
}

Functions