Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Functions to support theming in the Seven theme.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Form\FormStateInterface;
|
Chris@17
|
9 use Drupal\media\MediaForm;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Implements hook_preprocess_HOOK() for HTML document templates.
|
Chris@0
|
13 */
|
Chris@0
|
14 function seven_preprocess_html(&$variables) {
|
Chris@0
|
15 // If on a node add or edit page, add a node-layout class.
|
Chris@0
|
16 $path_args = explode('/', \Drupal::request()->getPathInfo());
|
Chris@0
|
17 if ($suggestions = theme_get_suggestions($path_args, 'page', '-')) {
|
Chris@0
|
18 foreach ($suggestions as $suggestion) {
|
Chris@0
|
19 if ($suggestion === 'page-node-edit' || strpos($suggestion, 'page-node-add') !== FALSE) {
|
Chris@0
|
20 $variables['attributes']['class'][] = 'node-form-layout';
|
Chris@0
|
21 }
|
Chris@0
|
22 }
|
Chris@0
|
23 }
|
Chris@0
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Implements hook_preprocess_HOOK() for menu-local-tasks templates.
|
Chris@0
|
28 *
|
Chris@0
|
29 * Use preprocess hook to set #attached to child elements
|
Chris@0
|
30 * because they will be processed by Twig and drupal_render will
|
Chris@0
|
31 * be invoked.
|
Chris@0
|
32 */
|
Chris@0
|
33 function seven_preprocess_menu_local_tasks(&$variables) {
|
Chris@0
|
34 if (!empty($variables['primary'])) {
|
Chris@0
|
35 $variables['primary']['#attached'] = [
|
Chris@0
|
36 'library' => [
|
Chris@0
|
37 'seven/drupal.nav-tabs',
|
Chris@0
|
38 ],
|
Chris@0
|
39 ];
|
Chris@0
|
40 }
|
Chris@0
|
41 elseif (!empty($variables['secondary'])) {
|
Chris@0
|
42 $variables['secondary']['#attached'] = [
|
Chris@0
|
43 'library' => [
|
Chris@0
|
44 'seven/drupal.nav-tabs',
|
Chris@0
|
45 ],
|
Chris@0
|
46 ];
|
Chris@0
|
47 }
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Implements hook_preprocess_HOOK() for menu-local-task templates.
|
Chris@0
|
52 */
|
Chris@0
|
53 function seven_preprocess_menu_local_task(&$variables) {
|
Chris@0
|
54 $variables['attributes']['class'][] = 'tabs__tab';
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Implements hook_preprocess_HOOK() for list of available node type templates.
|
Chris@0
|
59 */
|
Chris@0
|
60 function seven_preprocess_node_add_list(&$variables) {
|
Chris@0
|
61 if (!empty($variables['content'])) {
|
Chris@0
|
62 /** @var \Drupal\node\NodeTypeInterface $type */
|
Chris@0
|
63 foreach ($variables['content'] as $type) {
|
Chris@0
|
64 $variables['types'][$type->id()]['label'] = $type->label();
|
Chris@0
|
65 $variables['types'][$type->id()]['url'] = \Drupal::url('node.add', ['node_type' => $type->id()]);
|
Chris@0
|
66 }
|
Chris@0
|
67 }
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * Implements hook_preprocess_HOOK() for block content add list templates.
|
Chris@0
|
72 *
|
Chris@0
|
73 * Displays the list of available custom block types for creation, adding
|
Chris@0
|
74 * separate variables for the label and url.
|
Chris@0
|
75 */
|
Chris@0
|
76 function seven_preprocess_block_content_add_list(&$variables) {
|
Chris@0
|
77 if (!empty($variables['content'])) {
|
Chris@0
|
78 foreach ($variables['content'] as $type) {
|
Chris@0
|
79 $variables['types'][$type->id()]['label'] = $type->label();
|
Chris@0
|
80 $options = ['query' => \Drupal::request()->query->all()];
|
Chris@0
|
81 $variables['types'][$type->id()]['url'] = \Drupal::url('block_content.add_form', ['block_content_type' => $type->id()], $options);
|
Chris@0
|
82 }
|
Chris@0
|
83 }
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * Implements hook_preprocess_block() for block content.
|
Chris@0
|
88 *
|
Chris@0
|
89 * Disables contextual links for all blocks.
|
Chris@0
|
90 */
|
Chris@0
|
91 function seven_preprocess_block(&$variables) {
|
Chris@0
|
92 if (isset($variables['title_suffix']['contextual_links'])) {
|
Chris@0
|
93 unset($variables['title_suffix']['contextual_links']);
|
Chris@0
|
94 unset($variables['elements']['#contextual_links']);
|
Chris@0
|
95
|
Chris@0
|
96 $variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']);
|
Chris@0
|
97 }
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * Implements hook_preprocess_HOOK() for block admin page templates.
|
Chris@0
|
102 */
|
Chris@0
|
103 function seven_preprocess_admin_block_content(&$variables) {
|
Chris@0
|
104 if (!empty($variables['content'])) {
|
Chris@0
|
105 foreach ($variables['content'] as $key => $item) {
|
Chris@0
|
106 $variables['content'][$key]['url'] = $item['url']->toString();
|
Chris@0
|
107 }
|
Chris@0
|
108 }
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@0
|
111 /**
|
Chris@0
|
112 * Implements hook_preprocess_HOOK() for menu-local-action templates.
|
Chris@0
|
113 */
|
Chris@0
|
114 function seven_preprocess_menu_local_action(array &$variables) {
|
Chris@0
|
115 $variables['link']['#options']['attributes']['class'][] = 'button--primary';
|
Chris@0
|
116 $variables['link']['#options']['attributes']['class'][] = 'button--small';
|
Chris@0
|
117
|
Chris@0
|
118 // We require Modernizr's touch test for button styling.
|
Chris@0
|
119 $variables['#attached']['library'][] = 'core/modernizr';
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@0
|
122 /**
|
Chris@0
|
123 * Implements hook_element_info_alter().
|
Chris@0
|
124 */
|
Chris@0
|
125 function seven_element_info_alter(&$type) {
|
Chris@0
|
126 // We require Modernizr for button styling.
|
Chris@0
|
127 if (isset($type['button'])) {
|
Chris@0
|
128 $type['button']['#attached']['library'][] = 'core/modernizr';
|
Chris@0
|
129 }
|
Chris@0
|
130 }
|
Chris@0
|
131
|
Chris@0
|
132 /**
|
Chris@0
|
133 * Implements hook_preprocess_install_page().
|
Chris@0
|
134 */
|
Chris@0
|
135 function seven_preprocess_install_page(&$variables) {
|
Chris@0
|
136 // Seven has custom styling for the install page.
|
Chris@0
|
137 $variables['#attached']['library'][] = 'seven/install-page';
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 /**
|
Chris@0
|
141 * Implements hook_preprocess_maintenance_page().
|
Chris@0
|
142 */
|
Chris@0
|
143 function seven_preprocess_maintenance_page(&$variables) {
|
Chris@0
|
144 // Seven has custom styling for the maintenance page.
|
Chris@0
|
145 $variables['#attached']['library'][] = 'seven/maintenance-page';
|
Chris@0
|
146 }
|
Chris@0
|
147
|
Chris@0
|
148 /**
|
Chris@0
|
149 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
|
Chris@0
|
150 *
|
Chris@0
|
151 * Changes vertical tabs to container.
|
Chris@0
|
152 */
|
Chris@0
|
153 function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
Chris@0
|
154 $form['#theme'] = ['node_edit_form'];
|
Chris@0
|
155 $form['#attached']['library'][] = 'seven/node-form';
|
Chris@0
|
156
|
Chris@0
|
157 $form['advanced']['#type'] = 'container';
|
Chris@0
|
158 $form['meta']['#type'] = 'container';
|
Chris@0
|
159 $form['meta']['#access'] = TRUE;
|
Chris@0
|
160 $form['meta']['changed']['#wrapper_attributes']['class'][] = 'container-inline';
|
Chris@0
|
161 $form['meta']['author']['#wrapper_attributes']['class'][] = 'container-inline';
|
Chris@0
|
162
|
Chris@0
|
163 $form['revision_information']['#type'] = 'container';
|
Chris@0
|
164 $form['revision_information']['#group'] = 'meta';
|
Chris@0
|
165 }
|
Chris@0
|
166
|
Chris@0
|
167 /**
|
Chris@0
|
168 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\media\MediaForm.
|
Chris@0
|
169 */
|
Chris@0
|
170 function seven_form_media_form_alter(&$form, FormStateInterface $form_state) {
|
Chris@17
|
171 // Only attach CSS from core if this form comes from Media core, and not from
|
Chris@17
|
172 // the contrib Media Entity 1.x branch.
|
Chris@17
|
173 if (\Drupal::moduleHandler()->moduleExists('media') && $form_state->getFormObject() instanceof MediaForm) {
|
Chris@17
|
174 // @todo Revisit after https://www.drupal.org/node/2892304 is in. It
|
Chris@17
|
175 // introduces a footer region to these forms which will allow for us to
|
Chris@17
|
176 // display a top border over the published checkbox by defining a
|
Chris@17
|
177 // media-edit-form.html.twig template the same way node does.
|
Chris@17
|
178 $form['#attached']['library'][] = 'seven/media-form';
|
Chris@17
|
179 }
|
Chris@0
|
180 }
|