-
Notifications
You must be signed in to change notification settings - Fork 2
/
unl_cas.module
57 lines (48 loc) · 2.05 KB
/
unl_cas.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
use Drupal\user\UserInterface;
use Drupal\user\Entity\User;
/**
* Implements hook_install().
*/
function unl_cas_install() {
\Drupal::configFactory()->getEditable('user.settings')
->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)
->save(TRUE);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function unl_cas_form_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// Disable and hide things that shouldn't be altered when using the CAS module.
$form['account']['mail']['#disabled'] = TRUE;
$form['account']['cas_enabled']['#disabled'] = TRUE;
$form['account']['cas_username']['#disabled'] = TRUE;
$form['account']['name']['#disabled'] = TRUE;
$form['account']['pass']['#access'] = FALSE;
$form['account']['status']['#access'] = FALSE;
// We want anyone who can access this form to be able to edit a user's roles.
// We do this here because we don't want Site Admin to have the full
// 'Administer roles and permissions' permission.
$form['account']['roles']['#access'] = TRUE;
// If user isn't an Administrator, they can't assign 'coder' role.
$form['account']['roles']['coder']['#disabled'] = TRUE;
// Limit 'Cancel account' ability to only Super Administrators.
$form['actions']['delete']['#access'] = FALSE;
if (User::load(\Drupal::currentUser()->id())->hasRole('administrator')) {
$form['account']['roles']['coder']['#disabled'] = FALSE;
}
if (User::load(\Drupal::currentUser()->id())->hasRole('super_administrator')) {
$form['account']['roles']['coder']['#disabled'] = FALSE;
$form['actions']['delete']['#access'] = TRUE;
}
// Always disable the Administrator roles. They should be managed via Drush.
$form['account']['roles']['administrator']['#disabled'] = TRUE;
$form['account']['roles']['super_administrator']['#disabled'] = TRUE;
}
/**
* Implements hook_menu_links_discovered_alter().
*/
function unl_cas_menu_links_discovered_alter(&$links) {
unset($links['admin_toolbar_tools.extra_links:user.admin_create']);
unset($links['cas.bulk_add_users']);
}