diff --git a/includes/block.inc b/includes/block.inc new file mode 100644 index 0000000000000000000000000000000000000000..3b7dc7165b3852de901c3e9513f54d02fb6955e2 --- /dev/null +++ b/includes/block.inc @@ -0,0 +1,26 @@ +<?php + +/** + * @file + * Provides the necessary hooks for the block theme suggestions. + */ + +use \Drupal\block_content\BlockContentInterface; + +/** + * Implements hook_theme_suggestions_HOOK_alter(). + */ +function gesso_theme_suggestions_block_alter(array &$suggestions, array $variables) { + $content = $variables['elements']['content']; + if (isset($content['#block_content']) and $content['#block_content'] instanceof BlockContentInterface) { + $suggestions = []; + $bundle = $content['#block_content']->bundle(); + $view_mode = $content['#view_mode']; + $suggestions[] = 'block__' . $bundle; + $suggestions[] = 'block__' . $view_mode; + $suggestions[] = 'block__' . $bundle . '__' . $view_mode; + if (!empty($variables['elements']['#id'])) { + $suggestions[] = 'block__' . $variables['elements']['#id']; + } + } +} diff --git a/includes/field.inc b/includes/field.inc new file mode 100644 index 0000000000000000000000000000000000000000..61e32f490edeb41f2653769700ad84d8b3cc0517 --- /dev/null +++ b/includes/field.inc @@ -0,0 +1,10 @@ +<?php + +/** + * @file + * Field template functions. + */ + +function gesso_theme_suggestions_field_alter(&$suggestions, $variables) { + $suggestions[] = 'field__node__' . $variables['element']['#field_name'] . '__' . $variables['element']['#bundle'] . '__' . $variables['element']['#view_mode']; +} diff --git a/includes/form.inc b/includes/form.inc new file mode 100644 index 0000000000000000000000000000000000000000..37b52e7269947517edacd4cfb5e4064f961d6d50 --- /dev/null +++ b/includes/form.inc @@ -0,0 +1,30 @@ +<?php + +/** + * @file + * Form template functions. + */ + +/** + * Implements template_preprocess_input(). + */ +function gesso_preprocess_input(&$vars) { + $vars['required'] = isset($vars['element']['#required']) ? $vars['element']['#required'] : NULL; + $vars['type'] = isset($vars['element']['#attributes']['type']) ? $vars['element']['#attributes']['type'] : NULL; + $vars['dropbutton'] = isset($vars['element']['#dropbutton']) ? $vars['element']['#dropbutton'] : NULL; +} + +/** + * Implements template_preprocess_fieldset(). + */ +function gesso_preprocess_fieldset(&$vars) { + $vars['type'] = isset($vars['element']['#type']) ? $vars['element']['#type'] : NULL; +} + +/** + * Implements hook_theme_suggestions_HOOK_alter(). + */ +function gesso_theme_suggestions_form_alter(array &$suggestions, array $variables) { + $form_id = $variables['element']['#form_id']; + $suggestions[] = 'form__' . $form_id; +} \ No newline at end of file diff --git a/includes/html.inc b/includes/html.inc new file mode 100644 index 0000000000000000000000000000000000000000..122e8a0709c3dc828b0fec307c18352f26ed47cd --- /dev/null +++ b/includes/html.inc @@ -0,0 +1,42 @@ +<?php + +/** + * @file + * HTML template functions. + */ + +/** + * Implements hook_preprocess_html(). + */ +function gesso_preprocess_html(&$vars, $hook) { + // Add x-ua-compatible meta tag. + $vars['page']['#attached']['html_head'][] = [ + [ + '#tag' => 'meta', + '#attributes' => [ + 'http-equiv' => 'x-ua-compatible', + 'content' => 'ie=edge', + ], + ], + 'x_ua_compatible', + ]; +} + +/** + * Implements hook_preprocess_maintenance_page(). + */ +function gesso_preprocess_maintenance_page(&$vars, $hook) { + // While markup for normal pages is split into html.html.twig and + // page.html.twig, the markup for the maintenance page is all in the single + // maintenance-page.html.twig template. So, to have what’s done in + // gesso_preprocess_html() and gesso_preprocess_page() also happen + // on the maintenance page, it has to be called here. + gesso_preprocess_html($vars, $hook); + gesso_preprocess_page($vars, $hook); +} + +/** + * Implements hook_preprocess_page(). + */ +function gesso_preprocess_page(&$vars, $hook) { +} diff --git a/includes/navigation.inc b/includes/navigation.inc new file mode 100644 index 0000000000000000000000000000000000000000..0993fc3ea756ee224c44d272436af54a7e256e0e --- /dev/null +++ b/includes/navigation.inc @@ -0,0 +1,33 @@ +<?php + +/** + * Implements theme_preprocess_menu_local_tasks() + * + * @param $variables + */ + function gesso_preprocess_menu_local_tasks(&$variables) { + foreach (['primary', 'secondary'] as $type) { + $tabs = []; + + // Sort the tabs by #weight. + uasort($variables[$type], ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']); + + foreach (array_keys($variables[$type]) as $key) { + // Add the tab to a new array. + $tabs[$key] = [ + 'active' => $variables[$type][$key]['#active'], + 'url' => $variables[$type][$key]['#link']['url']->toString(), + 'text' => \Drupal\Component\Utility\Html::escape($variables[$type][$key]['#link']['title']) + ]; + + // Check if the tab should be shown by rendering the original. + $link = \Drupal::service('renderer')->render($variables[$type][$key]); + if (!$link) { + unset($tabs[$key]); + } + } + + // Overwrite the original tabs data. + $variables[$type] = $tabs; + } + } diff --git a/includes/taxonomy.inc b/includes/taxonomy.inc new file mode 100644 index 0000000000000000000000000000000000000000..a8ace9a596349b0948f706e67df9422a45ff49a9 --- /dev/null +++ b/includes/taxonomy.inc @@ -0,0 +1,14 @@ +<?php + +/** + * Implements theme_suggestions_taxonomy_term_alter() + * + * @param $suggestions + * @param $variables + */ +function gesso_theme_suggestions_taxonomy_term_alter(array &$suggestions, array $variables) { + $bundle = $variables['elements']['name']['#bundle']; + $view_mode = $variables['elements']['#view_mode']; + $suggestions[] = 'taxonomy_term__' . $view_mode; + $suggestions[] = 'taxonomy_term__' . $bundle . '__' . $view_mode; +} diff --git a/includes/views.inc b/includes/views.inc new file mode 100644 index 0000000000000000000000000000000000000000..559bfd1a8730f6a2a29e977694ff1f6c934a4646 --- /dev/null +++ b/includes/views.inc @@ -0,0 +1,52 @@ +<?php + +/** + * Implements views_theme_suggestions_views_view(). + */ +function views_theme_suggestions_views_view(array $variables) { + $suggestions = []; + $view = $variables['view']; + + $suggestions[] = 'views_view__' . $view->id(); + $suggestions[] = 'views_view__' . $view->current_display; + $suggestions[] = 'views_view__' . $view->id() . '__' . $view->current_display; + + return $suggestions; +} + +/** + * Implements views_theme_suggestions_views_view_unformatted(). + */ +function views_theme_suggestions_views_view_unformatted(array $variables) { + $suggestions = []; + $view = $variables['view']; + + $suggestions[] = 'views_view_unformatted__' . $view->id(); + $suggestions[] = 'views_view_unformatted__' . $view->current_display; + $suggestions[] = 'views_view_unformatted__' . $view->id() . '__' . $view->current_display; + + return $suggestions; +} + +/** + * Implements preprocess_views_view(). + */ +function gesso_preprocess_views_view(&$variables) { + $variables['path'] = $variables['view']->getRequest()->getPathInfo(); +} + +/** +* Implements hook_theme_suggestions_container_alter(). +*/ +function gesso_theme_suggestions_container_alter(array &$suggestions, array $variables) { + // A list of view names in which to exclude the container markup. + // Included views will use container--no-wrapper.html.twig instead of container.html.twig. + $exclude_views = [ + // 'example_view_machine_name', + ]; + if (isset($variables['element']['#name'])) { + if (in_array($variables['element']['#name'], $exclude_views)) { + $suggestions[] = 'container__no_wrapper'; + } + } +} diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index 03ab462e4a2398b6ec80111f3f90350ce5498672..6abbf2a162dd7e0b2fdfbee2f714735e6dd3cdaa 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -9,7 +9,18 @@ use Drupal\taxonomy\Entity\Term; use Drupal\Core\Datetime; use Drupal\Core\DateTimeZone; -require_once dirname(__FILE__) . '/uw_wcms_gesso/gesso/gesso.theme'; +/** + * @file + * Functions to support theming. + */ + +require_once dirname(__FILE__) . '/includes/block.inc'; +require_once dirname(__FILE__) . '/includes/field.inc'; +require_once dirname(__FILE__) . '/includes/form.inc'; +require_once dirname(__FILE__) . '/includes/html.inc'; +require_once dirname(__FILE__) . '/includes/navigation.inc'; +require_once dirname(__FILE__) . '/includes/taxonomy.inc'; +require_once dirname(__FILE__) . '/includes/views.inc'; /** * Implements hook_preprocess_HOOK().