-
Notifications
You must be signed in to change notification settings - Fork 0
/
berry.theme
68 lines (54 loc) · 2 KB
/
berry.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
<?php
/*
Add content-type to page templates suggestions,
so we can use page--CONTENT-TYPE.html.twig
*/
function berry_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$suggestions[] = 'page__' . $node->bundle();
}
}
/*
Field template suggestion
for some fields we just need the field content, without wrapperd and labels:
add fields names to $content_only_fields_single and $content_only_fields_multiple accordingly
*/
function berry_theme_suggestions_field_alter(&$suggestions, &$variables) {
$content_only_fields_single = array(
// drupal node title aka label
'title',
// fields used across content-types / paragraphs
'field_title',
'field_heading_type',
'field_content',
'field_text_image_title',
'field_text_image_content',
'field_image_position',
'field_link',
// image fields (useless here if we use field.0 ?)
'field_image',
// fields used in views: useless here, unless you use "Use field template" in field setting in view)
);
if (in_array($variables['element']['#field_name'], $content_only_fields_single)) {
$suggestions[] = 'field__content_only__single';
}
$content_only_fields_multiple = array(
'field_flexible_page_contents',
'field_cards',
'field_file',
);
if (in_array($variables['element']['#field_name'], $content_only_fields_multiple)) {
$suggestions[] = 'field__content_only__multiple';
}
}
/*
Add path-alias as body class
*/
function berry_preprocess_html(&$variables) {
$current_path = \Drupal::service('path.current')->getPath();
$path = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);
if ($current_alias) {
$current_alias = ltrim($current_alias, '/');
$variables['attributes']['class'][] = 'path-' . \Drupal\Component\Utility\Html::cleanCssIdentifier($current_alias);
}
}