-
Notifications
You must be signed in to change notification settings - Fork 0
/
opening_hours.module
76 lines (70 loc) · 2.1 KB
/
opening_hours.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
<?php
/**
* @file
* Module hooks.
*/
use Drupal\Component\Utility\Html;
/**
* Implements hook_theme().
*/
function opening_hours_theme($existing, $type, $theme, $path) {
return [
'opening_hours_widget' => [
'template' => 'opening-hours-widget',
'path' => $path . '/templates',
'variables' => [
'preview_widget' => NULL,
'widgets' => NULL,
'service_id' => NULL,
'display_title' => NULL,
'channel_id' => NULL,
'single_widget' => NULL,
'date' => NULL,
'from' => NULL,
'until' => NULL,
],
],
];
}
/**
* Implements hook_preprocess().
*/
function template_preprocess_opening_hours_widget(&$variables) {
$variables['widget_id'] = Html::getUniqueId('opening_hours');
}
/**
* Implements hook_token_info_alter().
*
* Add the missing token info for automatically detected tokens.
*/
function opening_hours_token_info_alter(&$info) {
$entities = \Drupal::service('entity_field.manager')->getFieldMap();
foreach ($entities as $entity_key => $entity) {
foreach ($entity as $field_key => $field) {
if ($field['type'] !== 'opening_hours') {
continue;
}
$token_key = sprintf('%s-%s', $entity_key, $field_key);
$info['tokens'][$token_key]['service'] = [
'name' => t('Opening Hours: Service ID'),
'description' => t('The service record ID.'),
];
$info['tokens'][$token_key]['service_label'] = [
'name' => t('Opening Hours: Service label'),
'description' => t('The service label.'),
];
$info['tokens'][$token_key]['channel'] = [
'name' => t('Opening Hours: Channel ID'),
'description' => t('The channel record ID.'),
];
$info['tokens'][$token_key]['channel_label'] = [
'name' => t('Opening Hours: Channel label'),
'description' => t('The channel label.'),
];
$info['tokens'][$token_key]['broken'] = [
'name' => t('Opening Hours: Broken link'),
'description' => t('Indicates if the service/channel link no longer exists in the Opening Hours platform.'),
];
}
}
}