Skip to content
Snippets Groups Projects
Commit f524d4d0 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-3759: adding includes needed for theming

parent 231fab2d
No related branches found
No related tags found
No related merge requests found
<?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'];
}
}
}
<?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'];
}
<?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
<?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) {
}
<?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;
}
}
<?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;
}
<?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';
}
}
}
......@@ -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().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment