-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlst_agldwg.module
148 lines (130 loc) · 4.8 KB
/
lst_agldwg.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* @file
* feedback form_alter and mail_alter hook functions for lst_agldwg.
*
* @ingroup lst_agldwg
*/
/**
* Implements hook_mail_alter to prepend '[LD-Registry] ' to
* the subject line of all outgoing emails.
*/
function lst_agldwg_mail_alter(&$message) {
if (isset($message['subject'])) {
$message['subject'] = '[LD Registry] ' . $message['subject'];
} else {
$message['subject'] = '[LD Registry]';
}
}
/**
* Implements hook_form_FORM_ID_alter to support prefilling subject
* (and possibly also the message)
* on the contact form when a query parameter 'subject' is supplied.
*/
function lst_agldwg_form_contact_message_feedback_form_alter(&$form,
$form_state,
$form_id) {
if (!empty($_GET['subject'])) {
$subject = $_GET['subject'];
$form['subject']['widget'][0]['value']['#default_value'] =
$subject;
// Support prefilling of the message field for the
// subject "Organisation+registration+request".
if ($subject == 'Organisation registration request') {
$form['message']['widget'][0]['value']['#default_value'] =
'Request for new Organisation Register Item
Please complete the following form.
A member of the AGLDWG will contact you if further information is required.
Name of organisation:
Alternative names (e.g., acronyms, prior names of the organisation):
Is the organisation a unit/section of another organisation?
If so, please specify:
Organisation homepage URL:
Identifiers, if available:
AGOR:
CRS:
GRID:
ROR:
';
}
}
}
/**
* Implements hook_form_alter for content types.
* Limit allowed reviewers to members of the Administrator and
* Control body roles, and any existing value for the field.
* Increase the height of the select list to 10,
* so that users don't need to scroll to see all of the allowed values.
* Remove comment settings for non-administrator users.
*/
function lst_agldwg_form_alter(&$form, $form_state, $form_id) {
// \Drupal::logger('agldwg module')->notice('in form alter');
// Only modify forms that have a "field_reviewer" field.
if (!empty($form['field_reviewer'])) {
// The array of options (i.e., all users) is:
// $form['field_reviewer']['widget']['#options']
// =>
// array (
// 0 => 'Anonymous',
// 1 => 'admin',
// ...)
// The array of current values of the field is:
// $form['field_reviewer']['widget']['#default_value']
// =>
// array (
// 0 => '6',
// )
// The allowed users are those who are in the administrator
// and control body roles, _and_ those who are already set
// as reviewers of this node. (This allows for someone to continue
// to be a reviewer who _was_ in the control body, but is no longer.)
$allowed_users = lst_agldwg_get_admin_and_control_body_uids();
// Add in the current values:
if (!empty($form['field_reviewer']['widget']['#default_value'])) {
foreach ($form['field_reviewer']['widget']['#default_value']
as $r) {
$allowed_users[$r] = $r;
}
}
$not_allowed_users = array_diff_key(
$form['field_reviewer']['widget']['#options'],
$allowed_users);
$form['field_reviewer']['widget']['#options'] =
array_diff($form['field_reviewer']['widget']['#options'],
$not_allowed_users);
// And while we're here, make the select list bigger, so that you
// don't need to scroll to see all the options.
$form['field_reviewer']['widget']['#size'] = 10;
}
// Only modify forms that have a "field_workflow" field.
if (!empty($form['field_workflow'])) {
// If the current user is not an administrator,
// remove the comment settings.
if (!\Drupal::currentUser()->hasPermission(
'administer site configuration')) {
unset($form['field_workflow']);
}
}
}
/**
* Helper function to get the uids of all users who are members
* of either the Administrator or Control Body roles.
*/
function lst_agldwg_get_admin_and_control_body_uids() {
$query = \Drupal::entityTypeManager()->getStorage('user')->getQuery();
$uids = $query
->accessCheck(FALSE)
->condition('status', '1')
->condition('roles', array('administrator', 'control_body'), 'IN')
->execute();
return $uids;
// The return value looks like:
// array (
// 1 => '1',
// 9 => '9',
// 10 => '10',
// 11 => '11',
// 34 => '34',
// 50 => '50',
// )
}