-
Notifications
You must be signed in to change notification settings - Fork 4
/
vartheme_bs4.theme
133 lines (111 loc) · 4.23 KB
/
vartheme_bs4.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
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
<?php
/**
* @file
* Functions to support Vartheme BS4 theme.
*/
use Drupal\node\NodeInterface;
use Drupal\node\Entity\Node;
/**
* Implements hook_theme_registry_alter().
*/
function vartheme_bs4_theme_registry_alter(&$theme_registry) {
// Varbase Bootstrap 4 path.
$vartheme_bs4_path = Drupal::service('theme_handler')->getTheme('vartheme_bs4')->getPath();
$theme_registry['entity_embed_container']['path'] = $vartheme_bs4_path . '/templates/entity-embed';
$pages = [
'page__user__login' => 'page--user--login',
'page__user__register' => 'page--user--register',
'page__user__password' => 'page--user--password',
'page__user__reset' => 'page--user--reset',
];
foreach ($pages as $key => $template) {
$theme_registry[$key]['path'] = $vartheme_bs4_path . '/templates/betterlogin';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function vartheme_bs4_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if (is_numeric($node)) {
$node = Node::load($node);
}
if ($node instanceof NodeInterface) {
array_splice($suggestions, 1, 0, 'page__' . $node->bundle());
}
}
}
/**
* Implements hook_preprocess_page_title().
*/
function vartheme_bs4_preprocess_page_title(&$variables) {
// Hide page title for the front page and let screen readers only see it.
if (\Drupal::service('path.matcher')->isFrontPage()) {
$variables['title_attributes']['class'][] = 'page-title';
$variables['title_attributes']['class'][] = 'sr-only';
}
}
/**
* Implements hook_preprocess_html().
*/
function vartheme_bs4_preprocess_html(&$variables) {
// The path for Vartheme BS4 theme in variables.
$variables['vartheme_bs4_path'] = \Drupal::request()->getBaseUrl() . '/' . \Drupal::service('extension.list.theme')->getPath('vartheme_bs4');
// Add information about the number of sidebars.
if (theme_get_setting('bootstrap_barrio_navbar_position')) {
$variables['navbar_position'] = theme_get_setting('bootstrap_barrio_navbar_position');
}
}
/**
* Implements hook_preprocess_page().
*/
function vartheme_bs4_preprocess_page(&$variables) {
// Add the pring logo.
$variables['logo_print'] = \Drupal::request()->getBaseUrl() . '/' . \Drupal::service('extension.list.theme')->getPath('vartheme_bs4') . '/logo-print.png';
// Add the site name and slogan.
$variables['site_name'] = \Drupal::config('system.site')->get('name');
$variables['site_slogan'] = \Drupal::config('system.site')->get('slogan');
}
/**
* Prepares variables for views grid templates.
*
* Default template: views-bootstrap-grid.html.twig.
*
* @param array $vars
* An associative array containing:
* - view: A ViewExecutable object.
* - rows: The raw row data.
*/
function vartheme_bs4_preprocess_views_bootstrap_grid(array &$vars) {
if (isset($vars['options']) && isset($vars['options']["col_xs"])) {
$vars['options']["col_xs"] = str_replace("xs-", "", $vars['options']["col_xs"]);
}
}
/**
* Implements hook_form_alter().
*/
function vartheme_bs4_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'content_moderation_entity_moderation_form') {
$form['#attributes']['class'][] = 'card card-body bg-light';
}
if ((preg_match('/^node_.*._layout_builder_form$/', $form_id)
&& isset($form['moderation_state']))) {
$form['moderation_state']['#attributes']['class'][] = 'card card-body bg-light';
$form['#attached']['library'][] = 'vartheme_bs4/moderation-state';
}
}
/**
* Implements hook_preprocess_login_with().
*/
function vartheme_bs4_preprocess_login_with(&$variables) {
foreach ($variables['social_networks'] as $social_network_index => $social_network) {
if (isset($social_network['img_path'])) {
$theme_path = Drupal::service('theme_handler')->getTheme('vartheme_bs4')->getPath();
$replaced_path_for_icons = str_replace('modules/contrib', 'social_auth', $social_network['img_path']);
$social_network_img_path_in_vartheme = $theme_path . '/images/' . $replaced_path_for_icons;
if (file_exists(DRUPAL_ROOT . '/' . $social_network_img_path_in_vartheme)) {
$variables['social_networks'][$social_network_index]['img_path'] = $social_network_img_path_in_vartheme;
}
}
}
}