5 * Functions to support theming in the Seven theme.
8 use Drupal\Core\Form\FormStateInterface;
11 * Implements hook_preprocess_HOOK() for HTML document templates.
13 function seven_preprocess_html(&$variables) {
14 // If on a node add or edit page, add a node-layout class.
15 $path_args = explode('/', \Drupal::request()->getPathInfo());
16 if ($suggestions = theme_get_suggestions($path_args, 'page', '-')) {
17 foreach ($suggestions as $suggestion) {
18 if ($suggestion === 'page-node-edit' || strpos($suggestion, 'page-node-add') !== FALSE) {
19 $variables['attributes']['class'][] = 'node-form-layout';
26 * Implements hook_preprocess_HOOK() for menu-local-tasks templates.
28 * Use preprocess hook to set #attached to child elements
29 * because they will be processed by Twig and drupal_render will
32 function seven_preprocess_menu_local_tasks(&$variables) {
33 if (!empty($variables['primary'])) {
34 $variables['primary']['#attached'] = [
36 'seven/drupal.nav-tabs',
40 elseif (!empty($variables['secondary'])) {
41 $variables['secondary']['#attached'] = [
43 'seven/drupal.nav-tabs',
50 * Implements hook_preprocess_HOOK() for menu-local-task templates.
52 function seven_preprocess_menu_local_task(&$variables) {
53 $variables['attributes']['class'][] = 'tabs__tab';
57 * Implements hook_preprocess_HOOK() for list of available node type templates.
59 function seven_preprocess_node_add_list(&$variables) {
60 if (!empty($variables['content'])) {
61 /** @var \Drupal\node\NodeTypeInterface $type */
62 foreach ($variables['content'] as $type) {
63 $variables['types'][$type->id()]['label'] = $type->label();
64 $variables['types'][$type->id()]['url'] = \Drupal::url('node.add', ['node_type' => $type->id()]);
70 * Implements hook_preprocess_HOOK() for block content add list templates.
72 * Displays the list of available custom block types for creation, adding
73 * separate variables for the label and url.
75 function seven_preprocess_block_content_add_list(&$variables) {
76 if (!empty($variables['content'])) {
77 foreach ($variables['content'] as $type) {
78 $variables['types'][$type->id()]['label'] = $type->label();
79 $options = ['query' => \Drupal::request()->query->all()];
80 $variables['types'][$type->id()]['url'] = \Drupal::url('block_content.add_form', ['block_content_type' => $type->id()], $options);
86 * Implements hook_preprocess_block() for block content.
88 * Disables contextual links for all blocks.
90 function seven_preprocess_block(&$variables) {
91 if (isset($variables['title_suffix']['contextual_links'])) {
92 unset($variables['title_suffix']['contextual_links']);
93 unset($variables['elements']['#contextual_links']);
95 $variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']);
100 * Implements hook_preprocess_HOOK() for block admin page templates.
102 function seven_preprocess_admin_block_content(&$variables) {
103 if (!empty($variables['content'])) {
104 foreach ($variables['content'] as $key => $item) {
105 $variables['content'][$key]['url'] = $item['url']->toString();
111 * Implements hook_preprocess_HOOK() for menu-local-action templates.
113 function seven_preprocess_menu_local_action(array &$variables) {
114 $variables['link']['#options']['attributes']['class'][] = 'button--primary';
115 $variables['link']['#options']['attributes']['class'][] = 'button--small';
117 // We require Modernizr's touch test for button styling.
118 $variables['#attached']['library'][] = 'core/modernizr';
122 * Implements hook_element_info_alter().
124 function seven_element_info_alter(&$type) {
125 // We require Modernizr for button styling.
126 if (isset($type['button'])) {
127 $type['button']['#attached']['library'][] = 'core/modernizr';
132 * Implements hook_preprocess_install_page().
134 function seven_preprocess_install_page(&$variables) {
135 // Seven has custom styling for the install page.
136 $variables['#attached']['library'][] = 'seven/install-page';
140 * Implements hook_preprocess_maintenance_page().
142 function seven_preprocess_maintenance_page(&$variables) {
143 // Seven has custom styling for the maintenance page.
144 $variables['#attached']['library'][] = 'seven/maintenance-page';
148 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
150 * Changes vertical tabs to container.
152 function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
153 $form['#theme'] = ['node_edit_form'];
154 $form['#attached']['library'][] = 'seven/node-form';
156 $form['advanced']['#type'] = 'container';
157 $form['meta']['#type'] = 'container';
158 $form['meta']['#access'] = TRUE;
159 $form['meta']['changed']['#wrapper_attributes']['class'][] = 'container-inline';
160 $form['meta']['author']['#wrapper_attributes']['class'][] = 'container-inline';
162 $form['revision_information']['#type'] = 'container';
163 $form['revision_information']['#group'] = 'meta';
167 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\media\MediaForm.
169 function seven_form_media_form_alter(&$form, FormStateInterface $form_state) {
170 // @todo Revisit after https://www.drupal.org/node/2892304 is in. It
171 // introduces a footer region to these forms which will allow for us to
172 // display a top border over the published checkbox by defining a
173 // media-edit-form.html.twig template the same way node does.
174 $form['#attached']['library'][] = 'seven/media-form';