-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcog.theme
44 lines (39 loc) · 1.28 KB
/
cog.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
<?php
/**
* @file
* Theme specific functionality.
*/
use Drupal\Component\Utility\Html;
/**
* Implements hook_preprocess_html().
*/
function cog_preprocess_html(&$variables) {
$system_path = \Drupal::service('path.current')->getPath();
$page_path = explode('/', $system_path)[1];
if (!empty($page_path)) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('path--' . $page_path);
}
}
/**
* Implements template_preprocess_block().
*/
function cog_preprocess_block(&$variables) {
// Custom block type helper classes.
if (isset($variables['elements']['content']['#block_content'])) {
$bundle = $variables['elements']['content']['#block_content']->bundle();
$bundle_class = str_replace('_', '-', $bundle);
if (isset($variables['attributes']['class'])) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('block--bundle-' . $bundle_class);
$variables['attributes']['data-bundle-class'] = $bundle_class;
}
}
}
/**
* Implements hook_preprocess_node().
*/
function cog_preprocess_node(&$variables) {
// Helper variables for multiple nodes.
if (!empty($variables['elements']['#entity_type'])) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('entity--type-' . $variables['elements']['#entity_type']);
}
}