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