-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_user_email.module
38 lines (33 loc) · 1.13 KB
/
view_user_email.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
<?php
/**
* @file
* Contains view_user_email.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Access\AccessResult;
/**
* Implements hook_help().
*/
function view_user_email_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the view_user_email module.
case 'help.page.view_user_email':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Allow site administrator the ability to grant users of certain roles access to another users email address.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_entity_field_access().
*/
function view_user_email_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL) {
if ($field_definition->getName() != 'mail' || $operation != 'view') {
return AccessResult::neutral();
}
if ($account->hasPermission('access email field')) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}