Implements hook_user_role_insert().
function user_user_role_insert(RoleInterface $role) {
// Ignore the authenticated and anonymous roles.
if (in_array($role
->id(), array(
DRUPAL_AUTHENTICATED_RID,
DRUPAL_ANONYMOUS_RID,
))) {
return;
}
$action = entity_create('action', array(
'id' => 'user_add_role_action.' . $role
->id(),
'type' => 'user',
'label' => t('Add the @label role to the selected users', array(
'@label' => $role
->label(),
)),
'configuration' => array(
'rid' => $role
->id(),
),
'plugin' => 'user_add_role_action',
));
$action
->save();
$action = entity_create('action', array(
'id' => 'user_remove_role_action.' . $role
->id(),
'type' => 'user',
'label' => t('Remove the @label role from the selected users', array(
'@label' => $role
->label(),
)),
'configuration' => array(
'rid' => $role
->id(),
),
'plugin' => 'user_remove_role_action',
));
$action
->save();
}