annotate core/themes/bartik/bartik.theme @ 19:fa3358dc1485 tip

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