-
Notifications
You must be signed in to change notification settings - Fork 0
/
varbase_components.module
103 lines (91 loc) · 3.44 KB
/
varbase_components.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
<?php
/**
* @file
* Contains varbase_components.module.
*/
/**
* Implements hook_theme().
*/
function varbase_components_theme($existing, $type, $theme, $path) {
return [
'media_oembed_iframe__remote_video__varbase_heroslider' => [
'template' => 'media-oembed-iframe--remote-video--varbase-heroslider',
'variables' => [
'provider' => NULL,
'media' => NULL,
],
],
];
}
/**
* Implements hook_preprocess_HOOK().
*/
function varbase_components_preprocess_media_oembed_iframe__remote_video__varbase_heroslider(&$variables) {
// Send variables for the remote_video varbase heroslier oembed iframe.
$query = \Drupal::request()->query;
$variables['type'] = $query->get('type');
$variables['provider'] = $query->get('provider');
$variables['view_mode'] = $query->get('view_mode');
$variables['base_path'] = base_path();
$variables['varbase_components_path'] = \Drupal::service('module_handler')->getModule('varbase_components')->getPath();
}
/**
* Implements hook_library_info_alter().
*/
function varbase_components_library_info_alter(array &$libraries, $module) {
if ($module === 'sitewide_alert' && isset($libraries['init'])) {
// Add the dependency only if it's not already present.
if (!in_array('core/components.varbase_components--alert', $libraries['init']['dependencies'])) {
$libraries['init']['dependencies'][] = 'core/components.varbase_components--alert';
}
unset($libraries['init']['css']);
}
// Load components styles for CKEditor5 styles.
if ($module === 'ckeditor5' && isset($libraries['internal.drupal.ckeditor5.stylesheets'])) {
$libraries['internal.drupal.ckeditor5.stylesheets']['dependencies'][] = 'varbase_components/ckeditor5-styles';
}
// Replace the Popper.js library file from the Responsive Theme preview module.
// Varbase Components and Vartheme BS5 need a different version which still
// works for the Responsive Theme preview module.
if ($module === 'responsive_preview'
&& isset($libraries['drupal.responsive-preview'])
&& isset($libraries['drupal.responsive-preview']['js'])
&& isset($libraries['drupal.responsive-preview']['js']['js/popperjs/popper.min.js'])) {
unset($libraries['drupal.responsive-preview']['js']['js/popperjs/popper.min.js']);
$libraries['drupal.responsive-preview']['dependencies'][] = 'varbase_components/popper-script';
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function varbase_components_preprocess_field(&$variables) {
$ckeditor5_fields = [
'text_with_summary',
'text_long',
];
// Check if the field type is in the list of CKEditor5 fields.
if (in_array($variables['field_type'], $ckeditor5_fields)) {
// Attach the library to the field.
$variables['#attached']['library'][] = 'varbase_components/ckeditor5-styles';
}
}
/**
* Implements hook_preprocess().
*/
function varbase_components_preprocess_menu(&$variables, $hook, $info) {
// Checks the nested level of a menu.
varbase_components_process_menu_level($variables['items']);
}
/**
* Add menu_link_level to menus.
*/
function varbase_components_process_menu_level(&$menu_items, $menu_level = 1) {
foreach ($menu_items as &$menu_item) {
// Set the menu level for the current item.
$menu_item['menu_link_level'] = $menu_level;
// If there are child items, process them recursively.
if (!empty($menu_item['below'])) {
varbase_components_process_menu_level($menu_item['below'], $menu_level + 1);
}
}
}