-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabp_core.module
executable file
·193 lines (173 loc) · 4.63 KB
/
abp_core.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* @file
* ABP Core module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_help().
*/
function abp_core_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the abp_core module.
case 'help.page.abp_core':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('ABP Core provides configuration that is intended to be used on top of the Drupal "standard" profile and accompanied with the ABP Theme.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function abp_core_theme() {
return [
'abp_core_event_details' => [
'variables' => [
'date' => NULL,
'time' => NULL,
'location' => NULL,
'link' => NULL,
],
],
'abp_core_belen_details' => [
'variables' => [
'artesanos_figuras' => NULL,
'ano_belen' => NULL,
'escena' => NULL,
'localizacion_belen' => NULL,
'tamano_belen' => NULL,
'tamano_figuras_belen' => NULL,
'tipo_belen' => NULL,
'galeria' => NULL,
],
],
'abp_core_newsletter' => [
'variables' => [
'action' => NULL,
'title' => NULL,
'description' => NULL,
],
],
'abp_core_map' => [
'variables' => [
'script' => NULL,
],
],
'abp_core_footer' => [
'variables' => [
'footer_col1' => NULL,
'footer_col2' => NULL,
'footer_col3' => NULL,
'footer_connect' => NULL,
'footer_facebook' => NULL,
'footer_twitter' => NULL,
'footer_youtube' => NULL,
'footer_instagram' => NULL,
],
],
];
}
/**
* Implements hook_entity_update().
*/
function abp_core_entity_update(EntityInterface $entity) {
// Only use custom aliases if PathAuto is not enabled.
if (!\Drupal::moduleHandler()->moduleExists('pathauto')) {
_abp_core_node_auto_alias($entity);
}
}
/**
* Implements hook_entity_insert().
*/
function abp_core_entity_insert(EntityInterface $entity) {
abp_core_entity_update($entity);
}
/**
* ABP node auto-alias patterns.
*
* Note: This is a fallback for when PathAuto is not enabled.
*
* @param Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*/
function _abp_core_node_auto_alias(EntityInterface $entity) {
$db = Drupal::database();
$aliases = [
'ministry' => '/ministry/',
'article' => '/article/',
'event' => '/event/',
'belen' => '/belen/',
'sermon' => '/sermons/',
];
if ($entity->getEntityTypeId() == 'node') {
if (isset($aliases[$entity->bundle()])) {
$node_alias_path = $aliases[$entity->bundle()];
}
else {
$node_alias_path = '/';
}
$nid = $entity->id();
// Get the node title.
$title = $entity->title->getValue()[0]['value'];
// Convert node title to machine path.
$alias = $machine_name = _abp_core_clean_alias($title);
$c = 0;
// Look for existing alias.
do {
$result = $db->query('SELECT id FROM {path_alias}
WHERE alias = :alias AND path != :source',
[
':alias' => $node_alias_path . $alias,
':source' => '/node/' . $nid,
]
)->fetchObject();
// If alias exists, increment.
if ($result) {
$alias = $machine_name . '-' . $c++;
}
else {
break;
}
} while ($result);
// Create the alias.
\Drupal::entityTypeManager()->getStorage('path_alias')->create([
'path' => '/node/' . $nid,
'alias' => $node_alias_path . $alias,
])->save();
}
}
/**
* ABP clean alias.
*
* @param string $text
* Text to clean.
*
* @return string
* Return machine name for text.
*/
function _abp_core_clean_alias($text) {
return preg_replace('/\-+/', '-', strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '', str_replace(' ', '-', $text))));
}
/**
* Implements hook_library_info_alter().
*/
function abp_core_library_info_alter(&$libraries, $extension) {
// Override CDN values with theme settings.
if ($extension == 'abp_theme') {
if ($bootstrap_css = theme_get_setting('bootstrap_css')) {
$libraries['bootstrap-css']['css']['component'] = [$bootstrap_css => []];
}
if ($bootstrap_js = theme_get_setting('bootstrap_js')) {
$libraries['bootstrap-js']['js'] = [$bootstrap_js => []];
}
if ($icons_css = theme_get_setting('icons_css')) {
$libraries['icons-css']['css']['component'] = [$icons_css => []];
}
if ($popper_js = theme_get_setting('popper_js')) {
$libraries['popper-js']['js'] = [$popper_js => []];
}
}
}