Chris@3
|
1 <?php
|
Chris@3
|
2
|
Chris@3
|
3 /**
|
Chris@3
|
4 * @file
|
Chris@3
|
5 * Functions to support theming in the Bartik theme.
|
Chris@3
|
6 */
|
Chris@3
|
7
|
Chris@3
|
8 use Drupal\Core\Form\FormStateInterface;
|
Chris@3
|
9 use Drupal\Core\Template\Attribute;
|
Chris@3
|
10
|
Chris@3
|
11 /**
|
Chris@3
|
12 * Implements hook_preprocess_HOOK() for HTML document templates.
|
Chris@3
|
13 *
|
Chris@3
|
14 * Adds body classes if certain regions have content.
|
Chris@3
|
15 */
|
Chris@3
|
16 function isobartik_preprocess_html(&$variables) {
|
Chris@3
|
17 // Add information about the number of sidebars.
|
Chris@3
|
18 if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
|
Chris@3
|
19 $variables['attributes']['class'][] = 'layout-two-sidebars';
|
Chris@3
|
20 }
|
Chris@3
|
21 elseif (!empty($variables['page']['sidebar_first'])) {
|
Chris@3
|
22 $variables['attributes']['class'][] = 'layout-one-sidebar';
|
Chris@3
|
23 $variables['attributes']['class'][] = 'layout-sidebar-first';
|
Chris@3
|
24 }
|
Chris@3
|
25 elseif (!empty($variables['page']['sidebar_second'])) {
|
Chris@3
|
26 $variables['attributes']['class'][] = 'layout-one-sidebar';
|
Chris@3
|
27 $variables['attributes']['class'][] = 'layout-sidebar-second';
|
Chris@3
|
28 }
|
Chris@3
|
29 else {
|
Chris@3
|
30 $variables['attributes']['class'][] = 'layout-no-sidebars';
|
Chris@3
|
31 }
|
Chris@3
|
32
|
Chris@3
|
33 if (!empty($variables['page']['featured_top'])) {
|
Chris@3
|
34 $variables['attributes']['class'][] = 'has-featured-top';
|
Chris@3
|
35 }
|
Chris@3
|
36
|
Chris@3
|
37 }
|
Chris@3
|
38
|
Chris@3
|
39 /**
|
Chris@3
|
40 * Implements hook_preprocess_HOOK() for page templates.
|
Chris@3
|
41 */
|
Chris@3
|
42 function isobartik_preprocess_page_title(&$variables) {
|
Chris@3
|
43 // Since the title and the shortcut link are both block level elements,
|
Chris@3
|
44 // positioning them next to each other is much simpler with a wrapper div.
|
Chris@3
|
45 if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
|
Chris@3
|
46 // Add a wrapper div using the title_prefix and title_suffix render
|
Chris@3
|
47 // elements.
|
Chris@3
|
48 $variables['title_prefix']['shortcut_wrapper'] = [
|
Chris@3
|
49 '#markup' => '<div class="shortcut-wrapper clearfix">',
|
Chris@3
|
50 '#weight' => 100,
|
Chris@3
|
51 ];
|
Chris@3
|
52 $variables['title_suffix']['shortcut_wrapper'] = [
|
Chris@3
|
53 '#markup' => '</div>',
|
Chris@3
|
54 '#weight' => -99,
|
Chris@3
|
55 ];
|
Chris@3
|
56 // Make sure the shortcut link is the first item in title_suffix.
|
Chris@3
|
57 $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
|
Chris@3
|
58 }
|
Chris@3
|
59 }
|
Chris@3
|
60
|
Chris@3
|
61 /**
|
Chris@3
|
62 * Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
|
Chris@3
|
63 */
|
Chris@3
|
64 function isobartik_preprocess_maintenance_page(&$variables) {
|
Chris@3
|
65 // By default, site_name is set to Drupal if no db connection is available
|
Chris@3
|
66 // or during site installation. Setting site_name to an empty string makes
|
Chris@3
|
67 // the site and update pages look cleaner.
|
Chris@3
|
68 // @see template_preprocess_maintenance_page
|
Chris@3
|
69 if (!$variables['db_is_active']) {
|
Chris@3
|
70 $variables['site_name'] = '';
|
Chris@3
|
71 }
|
Chris@3
|
72
|
Chris@3
|
73 // Bartik has custom styling for the maintenance page.
|
Chris@4
|
74 $variables['#attached']['library'][] = 'isobartik/maintenance_page';
|
Chris@3
|
75 }
|
Chris@3
|
76
|
Chris@3
|
77 /**
|
Chris@3
|
78 * Implements hook_preprocess_HOOK() for node.html.twig.
|
Chris@3
|
79 */
|
Chris@3
|
80 function isobartik_preprocess_node(&$variables) {
|
Chris@3
|
81 // Remove the "Add new comment" link on teasers or when the comment form is
|
Chris@3
|
82 // displayed on the page.
|
Chris@3
|
83 if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) {
|
Chris@3
|
84 unset($variables['content']['links']['comment']['#links']['comment-add']);
|
Chris@3
|
85 }
|
Chris@3
|
86 }
|
Chris@3
|
87
|
Chris@3
|
88 /**
|
Chris@3
|
89 * Implements hook_preprocess_HOOK() for block.html.twig.
|
Chris@3
|
90 */
|
Chris@3
|
91 function isobartik_preprocess_block(&$variables) {
|
Chris@3
|
92 // Add a clearfix class to system branding blocks.
|
Chris@3
|
93 if ($variables['plugin_id'] == 'system_branding_block') {
|
Chris@3
|
94 $variables['attributes']['class'][] = 'clearfix';
|
Chris@3
|
95 }
|
Chris@3
|
96 }
|
Chris@3
|
97
|
Chris@3
|
98 /**
|
Chris@3
|
99 * Implements hook_preprocess_HOOK() for menu.html.twig.
|
Chris@3
|
100 */
|
Chris@3
|
101 function isobartik_preprocess_menu(&$variables) {
|
Chris@3
|
102 $variables['attributes']['class'][] = 'clearfix';
|
Chris@3
|
103 }
|
Chris@3
|
104
|
Chris@3
|
105 /**
|
Chris@3
|
106 * Implements hook_theme_suggestions_HOOK_alter() for form templates.
|
Chris@3
|
107 */
|
Chris@3
|
108 function isobartik_theme_suggestions_form_alter(array &$suggestions, array $variables) {
|
Chris@3
|
109 if ($variables['element']['#form_id'] == 'search_block_form') {
|
Chris@3
|
110 $suggestions[] = 'form__search_block_form';
|
Chris@3
|
111 }
|
Chris@3
|
112 }
|
Chris@3
|
113
|
Chris@3
|
114 /**
|
Chris@3
|
115 * Implements hook_form_alter() to add classes to the search form.
|
Chris@3
|
116 */
|
Chris@3
|
117 function isobartik_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
Chris@3
|
118 if (in_array($form_id, ['search_block_form', 'search_form'])) {
|
Chris@3
|
119 $key = ($form_id == 'search_block_form') ? 'actions' : 'basic';
|
Chris@3
|
120 if (!isset($form[$key]['submit']['#attributes'])) {
|
Chris@3
|
121 $form[$key]['submit']['#attributes'] = new Attribute();
|
Chris@3
|
122 }
|
Chris@3
|
123 $form[$key]['submit']['#attributes']->addClass('search-form__submit');
|
Chris@3
|
124 }
|
Chris@3
|
125 }
|