annotate core/themes/seven/seven.theme @ 0:4c8ae668cc8c

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