forked from openeuropa/oe_bootstrap_theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe_bootstrap_theme.theme
95 lines (78 loc) · 2.94 KB
/
oe_bootstrap_theme.theme
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
<?php
/**
* @file
* The oe_bootstrap_theme hooks.
*/
declare(strict_types=1);
use Drupal\Core\Template\Attribute;
// Include all files from the includes directory.
$includes_path = __DIR__ . '/includes/*.inc';
foreach (glob($includes_path) as $filename) {
// The inspection disallowing basename() is not relevant for known paths.
// phpcs:ignore QualityAssurance.Functions.DrupalWrappers.FoundWithAlternative
require_once __DIR__ . '/includes/' . basename($filename);
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for table.
*/
function oe_bootstrap_theme_theme_suggestions_table_alter(array &$suggestions, array $variables) {
if (!theme_get_setting('bootstrap_tables.enable')) {
return;
}
$extra_suggestions[] = 'table__bootstrap';
$responsive = theme_get_setting('bootstrap_tables.responsive');
if (is_string($responsive) && $responsive !== '') {
$extra_suggestions[] = 'table__bootstrap__responsive';
}
// Add the new suggestions first in the list, so existing child theme
// overrides will keep precedence.
array_unshift($suggestions, ...$extra_suggestions);
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for views-view-table.
*/
function oe_bootstrap_theme_theme_suggestions_views_view_table_alter(array &$suggestions, array $variables) {
if (!theme_get_setting('bootstrap_tables.enable')) {
return;
}
$extra_suggestions[] = 'views_view_table__bootstrap';
$responsive = theme_get_setting('bootstrap_tables.responsive');
if (is_string($responsive) && $responsive !== '') {
$extra_suggestions[] = 'views_view_table__bootstrap__responsive';
}
// Add the new suggestions first in the list, so existing child theme
// overrides will keep precedence.
array_unshift($suggestions, ...$extra_suggestions);
}
/**
* Implements hook_preprocess().
*/
function oe_bootstrap_theme_preprocess(&$variables) {
$variables['bcl_icon_path'] = base_path() . \Drupal::service('extension.list.theme')->getPath('oe_bootstrap_theme') . '/assets/icons/bcl-default-icons.svg';
}
/**
* Implements hook_preprocess_HOOK() for table--bootstrap--responsive.html.twig.
*/
function oe_bootstrap_theme_preprocess_table__bootstrap__responsive(&$variables) {
_oe_bootstrap_theme_bootstrap_responsive_table($variables);
}
/**
* Implements hook_preprocess_HOOK() for views-view-table--bootstrap--responsive.html.twig.
*/
function oe_bootstrap_theme_preprocess_views_view_table__bootstrap__responsive(&$variables) {
_oe_bootstrap_theme_bootstrap_responsive_table($variables);
}
/**
* Function that applies responsiveness to Bootstrap tables.
*
* @param array $variables
* The variables to process.
*/
function _oe_bootstrap_theme_bootstrap_responsive_table(array &$variables): void {
$class = 'table-responsive';
$breakpoint = theme_get_setting('bootstrap_tables.responsive');
if ($breakpoint !== 'always') {
$class .= '-' . $breakpoint;
}
$variables['wrapper_attributes'] = new Attribute(['class' => $class]);
}