-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldbase_content.module
More file actions
150 lines (140 loc) · 5.1 KB
/
ldbase_content.module
File metadata and controls
150 lines (140 loc) · 5.1 KB
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
149
150
<?php
/**
* @file
* Contains ldbase_content.module.
*/
/**
* Implements hook_node_view().
*/
function ldbase_content_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
$hierarchichal_ctypes = array('project', 'dataset', 'code', 'document', 'codebook');
$ldbase_ctypes = array('project', 'dataset', 'code', 'document', 'person', 'organization', 'codebook');
$ctype = \Drupal::service('ldbase.object_service')->isLdbaseCodebook($entity->uuid()) ? 'codebook' : $entity->bundle();
if (in_array($ctype, $hierarchichal_ctypes)) {
$build['#attached']['library'][] = 'ldbase_content/breadcrumb-current-page-prefixer';
}
if (in_array($ctype, $ldbase_ctypes)) {
$title = $build['title'][0]['#context']['value'];
$prefixed_title = t('@ctype: @title', ['@ctype' => ucfirst($ctype), '@title' => $title]);
$build['title'][0]['#context']['value'] = $prefixed_title;
}
if ($ctype = 'dataset') {
$file = [];
if (!empty($entity->field_dataset_version)) {
foreach ($entity->field_dataset_version as $delta => $file_metadata_paragraph) {
$p = $file_metadata_paragraph->entity;
$file[$delta]['dataset_version_id'] = $p->field_file_version_id->value;
}
}
if (!empty($file)) {
$latest_version = array_pop($file);
$version_suffix = ' [v.' . $latest_version['dataset_version_id'] . ']';
$build['title'][0]['#context']['value'] .= $version_suffix;
}
}
}
/**
* Implements hook_form_alter().
*/
function ldbase_content_form_alter(&$form, Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'user_login_form') {
// change username label to Email Address
$form['name']['#title'] = t('Email Address');
$form['name']['#description'] = t('Enter your LDbase account email address.');
$form['pass']['#description'] = t('Enter the password that accompanies your LDbase account.');
}
if ($form_id == 'user_pass') {
$form['name']['#title'] = t('Email Address');
$form['mail'] = [
'#prefix' => '<p>',
'#markup' => t('Password reset instructions will be sent to your registered email address. If you cannot access your registered email (e.g., you have moved institutions), then please do not start a new account and instead email <a href="mailto:[email protected]">[email protected]</a> for assistance'),
'#suffix' => '</p>',
];
}
}
/**
* Implements hook_preprocess_HOOK().
*
* @param $variables
*/
function ldbase_content_preprocess_status_messages(&$variables) {
// modify error message for login from home and user.login
$change_login_error_messages = ['ldbase.home','user.login'];
$current_route = \Drupal::routeMatch()->getRouteName();
if (in_array($current_route, $change_login_error_messages)) {
if(isset($variables['message_list']['error'])){
$status_messages = $variables['message_list']['error'];
foreach($status_messages as $delta => $message) {
if (strpos((string) $message, '1 error has been found') !== FALSE) {
$variables['message_list']['error'][$delta] = "Unrecognized username or password.";
}
}
}
}
}
/**
* Implements hook_system_breadcrumb_alter().
*/
function ldbase_content_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$breadcrumb, \Drupal\Core\Routing\RouteMatchInterface $route_match, array $context) {
if ($route_match && $node = $route_match->getParameter('node')) {
$breadcrumb->addCacheableDependency($node);
}
}
/**
* Implements hook_theme().
*/
function ldbase_content_theme($existing, $type, $theme, $path) {
return [
'ldbase_content_browse_vocabularies' => [
'template' => 'ldbase-content-browse-vocabularies',
'variables' => [
'count' => NULL,
'vocabulary_links' => [],
],
],
'ldbase_content_home_page_user_block' => [
'template' => 'ldbase-content-home-page-user-block',
'variables' => [
'person_name' => NULL,
'person_orcid' => NULL,
'person_email' => NULL,
'person_related_organizations' => NULL,
'person_professional_titles' => [],
'dashboard_link' => NULL,
'messages_link' => NULL,
'favorites_link' => NULL,
'contributions_link' => NULL,
'profile_edit_link' => NULL,
'email_needs_verification' => NULL,
'verification_link' => NULL,
],
],
'ldbase_d3_contributions_block' => [
'template' => 'ldbase-d3-visualization-block',
'variables' => [
'description' => NULL,
],
],
'ldbase_d3_content_count_block' => [
'template' => 'ldbase-d3-visualization-block',
'variables' => [
'description' => NULL,
],
],
'ldbase_project_subtree' => [
'template' => 'ldbase-project-subtree',
'variables' => [
'subtree_title' => NULL,
'items' => NULL,
],
],
'ldbase_latest_project_items' => [
'template' => 'ldbase-latest-project-items',
'variables' => [
'section_prefix' => NULL,
'section_suffix' => NULL,
'block_data' => [],
]
]
];
}