-
Notifications
You must be signed in to change notification settings - Fork 1
/
asu_events.module
79 lines (69 loc) · 2.73 KB
/
asu_events.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
<?php
use Drupal\Core\Url;
/**
* Implements hook_preprocess_HOOK().
*/
function asu_events_preprocess_block(&$variables) {
$plugin_id = $variables['base_plugin_id'] ?? '';
if ($plugin_id != 'inline_block') {
return;
}
if ($variables['derivative_plugin_id'] == 'events') {
$rand_id = random_int(0, PHP_INT_MAX);
$events_block = (object)[
'header' => new \stdClass(),
'ctaButton' => new \stdClass(),
'dataSource' => new \stdClass(),
];
$variables['events_id'] = 'events-wrapper-' . $rand_id;
$block = $variables['content']['#block_content'];
if ($block->field_events_heading->value) {
$events_block->header->text = $block->field_events_heading->value;
}
if ($block->field_events_header_text_color->value) {
$events_block->header->color = $block->field_events_header_text_color->value;
}
if ($block->field_events_cta && $block->field_events_cta->title && $block->field_events_cta->uri) {
$events_block->ctaButton->text = $block->field_events_cta->title;
$link = Url::fromUri($block->field_events_cta->uri);
$events_block->ctaButton->url = $link->toString();
}
if ($block->field_events_cta_color->value) {
$events_block->ctaButton->color = $block->field_events_cta_color->value;
}
if ($block->field_events_items_to_display->value) {
$events_block->display = $block->field_events_items_to_display->value;
}
$events_block->dataSource->url = '/asu-events-feed/';
if ($block->field_feed_taxonomy_term->value) {
// Allow only alphanumeric characters and underscore.
$events_block->dataSource->url .= preg_replace('/[^A-Za-z0-9\_]/', '', $block->field_feed_taxonomy_term->value);
}
if ($block->field_events_feed_filter->value) {
$events_block->dataSource->filters = $block->field_events_feed_filter->value;
}
$settings = [];
$settings['components']['asu_events'][$rand_id] = $events_block;
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
$variables['content']['#attached']['library'][] = 'asu_events/events-component';
}
}
/**
* Implements hook_config_readonly_whitelist_patterns();
* Make all the config files from this module readonly.
* @return array
*/
function asu_events_config_readonly_whitelist_patterns() {
// Get all the module configuration files.
$module = \Drupal::service('module_handler')
->getModule(basename(__FILE__, '.module'))
->getName();
$configs = \Drupal::service('webspark.config_manager')->getModuleConfigFiles($module);
// Lock all the configurations from this module.
if (\Drupal::state()->get('configuration_locked', TRUE)) {
return array_map(function ($item) { return '~' . $item; }, $configs);
}
else {
return [];
}
}