2009-07-31 19:35:57 +00:00
|
|
|
<?php
|
|
|
|
|
2010-05-12 09:22:24 +00:00
|
|
|
/**
|
2012-04-19 15:30:31 +00:00
|
|
|
* @file
|
|
|
|
* Functions to support theming in the Seven theme.
|
|
|
|
*/
|
|
|
|
|
2014-04-07 15:01:20 +00:00
|
|
|
use Drupal\Component\Utility\Xss;
|
2014-02-08 20:57:42 +00:00
|
|
|
use Drupal\Component\Utility\String;
|
2014-07-31 00:50:42 +00:00
|
|
|
use Drupal\Core\Form\FormStateInterface;
|
2013-07-14 20:17:23 +00:00
|
|
|
|
2013-10-21 09:26:54 +00:00
|
|
|
/**
|
2014-01-01 20:32:52 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for page templates.
|
2013-10-21 09:26:54 +00:00
|
|
|
*/
|
2014-01-01 20:32:52 +00:00
|
|
|
function seven_preprocess_page(&$variables) {
|
|
|
|
/** @var \Drupal\Core\Page\HtmlPage $page_object */
|
|
|
|
$page_object = $variables['page']['#page'];
|
|
|
|
$attributes = $page_object->getBodyAttributes();
|
|
|
|
$classes = $attributes['class'];
|
2013-10-21 09:26:54 +00:00
|
|
|
// Add information about the number of sidebars.
|
2014-01-01 20:32:52 +00:00
|
|
|
|
2013-10-21 09:26:54 +00:00
|
|
|
if (!empty($variables['page']['sidebar_first'])) {
|
2014-06-13 18:57:27 +00:00
|
|
|
$classes[] = 'layout-one-sidebar';
|
|
|
|
$classes[] = 'layout-sidebar-first';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-06-13 18:57:27 +00:00
|
|
|
$classes[] = 'layout-no-sidebars';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
2014-01-01 20:32:52 +00:00
|
|
|
$attributes['class'] = $classes;
|
2013-10-21 09:26:54 +00:00
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
$variables['primary_local_tasks'] = $variables['tabs'];
|
|
|
|
unset($variables['primary_local_tasks']['#secondary']);
|
|
|
|
$variables['secondary_local_tasks'] = array(
|
2010-11-20 04:03:51 +00:00
|
|
|
'#theme' => 'menu_local_tasks',
|
2013-07-13 10:29:57 +00:00
|
|
|
'#secondary' => isset($variables['tabs']['#secondary']) ? $variables['tabs']['#secondary'] : '',
|
2010-11-20 04:03:51 +00:00
|
|
|
);
|
2009-07-31 19:35:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 20:57:42 +00:00
|
|
|
/**
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Implements hook_pre_render_HOOK() for menu-local-tasks templates.
|
2014-02-08 20:57:42 +00:00
|
|
|
*
|
2014-09-18 14:27:00 +00:00
|
|
|
* Use preprocess hook to set #attached to child elements
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* because they will be processed by Twig and drupal_render will
|
|
|
|
* be invoked.
|
2014-06-09 23:20:35 +00:00
|
|
|
*/
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
function seven_preprocess_menu_local_tasks(&$variables) {
|
2014-02-08 20:57:42 +00:00
|
|
|
if (!empty($variables['primary'])) {
|
|
|
|
$variables['primary']['#attached'] = array(
|
|
|
|
'library' => array(
|
2014-03-09 19:59:45 +00:00
|
|
|
'seven/drupal.nav-tabs',
|
2014-02-08 20:57:42 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
elseif (!empty($variables['secondary'])) {
|
2014-02-08 20:57:42 +00:00
|
|
|
$variables['secondary']['#attached'] = array(
|
|
|
|
'library' => array(
|
2014-03-09 19:59:45 +00:00
|
|
|
'seven/drupal.nav-tabs',
|
2014-02-08 20:57:42 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for menu-local-task templates.
|
2014-06-09 23:20:35 +00:00
|
|
|
*/
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
function seven_preprocess_menu_local_task(&$variables) {
|
|
|
|
$variables['attributes']['class'][] = 'tabs__tab';
|
2014-02-08 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 19:35:57 +00:00
|
|
|
/**
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for list of available node type templates.
|
2009-07-31 19:35:57 +00:00
|
|
|
*/
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
function seven_preprocess_node_add_list(&$variables) {
|
|
|
|
if (!empty($variables['content'])) {
|
|
|
|
foreach ($variables['content'] as $type) {
|
|
|
|
$variables['types'][$type->type]['label'] = String::checkPlain($type->name);
|
|
|
|
$variables['types'][$type->type]['description'] = Xss::filterAdmin($type->description);
|
|
|
|
$variables['types'][$type->type]['url'] = \Drupal::url('node.add', array('node_type' => $type->type));
|
2009-07-31 19:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 22:17:49 +00:00
|
|
|
/**
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for block content add list templates.
|
2013-02-18 22:17:49 +00:00
|
|
|
*
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
* Displays the list of available custom block types for creation, adding
|
|
|
|
* separate variables for the label, description, and url.
|
2013-02-18 22:17:49 +00:00
|
|
|
*/
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
function seven_preprocess_block_content_add_list(&$variables) {
|
|
|
|
if (!empty($variables['content'])) {
|
|
|
|
foreach ($variables['content'] as $type) {
|
|
|
|
$variables['types'][$type->id()]['label'] = String::checkPlain($type->label());
|
|
|
|
$variables['types'][$type->id()]['description'] = Xss::filterAdmin($type->description);
|
|
|
|
$options = array('query' => \Drupal::request()->query->all());
|
|
|
|
$variables['types'][$type->id()]['url'] = \Drupal::url('block_content.add_form', array('block_content_type' => $type->id()), $options);
|
2013-02-18 22:17:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 19:35:57 +00:00
|
|
|
/**
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for block admin page templates.
|
2009-07-31 19:35:57 +00:00
|
|
|
*/
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
function seven_preprocess_admin_block_content(&$variables) {
|
|
|
|
if (!empty($variables['content'])) {
|
|
|
|
foreach ($variables['content'] as $key => $item) {
|
2014-07-30 12:04:04 +00:00
|
|
|
$variables['content'][$key]['url'] = $item['url']->toString();
|
2009-07-31 19:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for tablesort indicator templates.
|
2009-07-31 19:35:57 +00:00
|
|
|
*
|
2012-04-19 15:30:31 +00:00
|
|
|
* Uses Seven's image versions, so the arrows show up as black and not gray on
|
|
|
|
* gray.
|
2009-07-31 19:35:57 +00:00
|
|
|
*/
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
function seven_preprocess_tablesort_indicator(&$variables) {
|
2009-07-31 19:35:57 +00:00
|
|
|
$theme_path = drupal_get_path('theme', 'seven');
|
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
2014-07-04 17:27:35 +00:00
|
|
|
$variables['arrow_asc'] = file_create_url($theme_path . '/images/arrow-asc.png');
|
|
|
|
$variables['arrow_desc'] = file_create_url($theme_path . '/images/arrow-desc.png');
|
2009-07-31 19:35:57 +00:00
|
|
|
}
|
2009-08-12 11:32:07 +00:00
|
|
|
|
2013-11-23 00:23:37 +00:00
|
|
|
/**
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for menu-local-action templates.
|
2013-11-23 00:23:37 +00:00
|
|
|
*/
|
Issue #1898478 by joelpittet, Cottser, lokapujya, m1r1k, jstoller, er.pushpinderrana, duellj, organicwire, jessebeach, idflood, Jalandhar, Risse, derheap, galooph, mike.roberts, tlattimore, nadavoid, LinL, steveoliver, chakrapani, likin, killerpoke, EVIIILJ, vlad.dancer, podarok, m86 | c4rl: Menu.inc - Convert theme_ functions to Twig.
2014-09-09 16:12:26 +00:00
|
|
|
function seven_preprocess_menu_local_action(array &$variables) {
|
|
|
|
$variables['link']['#options']['attributes']['class'][] = 'button--primary';
|
|
|
|
$variables['link']['#options']['attributes']['class'][] = 'button--small';
|
2013-11-23 00:23:37 +00:00
|
|
|
|
|
|
|
// We require Modernizr's touch test for button styling.
|
2014-10-08 11:49:20 +00:00
|
|
|
$variables['#attached']['library'][] = 'core/modernizr';
|
2013-11-23 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_element_info_alter().
|
|
|
|
*/
|
|
|
|
function seven_element_info_alter(&$type) {
|
|
|
|
// We require Modernizr for button styling.
|
|
|
|
if (isset($type['button'])) {
|
2014-03-09 19:59:45 +00:00
|
|
|
$type['button']['#attached']['library'][] = 'core/modernizr';
|
2013-11-23 00:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 08:52:15 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_install_page().
|
|
|
|
*/
|
|
|
|
function seven_preprocess_install_page(&$variables) {
|
2014-04-17 20:12:22 +00:00
|
|
|
$page_object = $variables['page']['#page'];
|
|
|
|
$attributes = $page_object->getHtmlAttributes();
|
|
|
|
$classes = $attributes['class'];
|
|
|
|
$classes[] = 'install-background';
|
|
|
|
$attributes['class'] = $classes;
|
2013-08-30 15:22:28 +00:00
|
|
|
|
2014-10-08 11:49:20 +00:00
|
|
|
// Seven has custom styling for the install page.
|
|
|
|
$variables['#attached']['library'][] = 'seven/install-page';
|
2014-03-26 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_maintenance_page().
|
|
|
|
*/
|
|
|
|
function seven_preprocess_maintenance_page(&$variables) {
|
2014-04-17 20:12:22 +00:00
|
|
|
$page_object = $variables['page']['#page'];
|
|
|
|
$attributes = $page_object->getHtmlAttributes();
|
|
|
|
$classes = $attributes['class'];
|
|
|
|
$classes[] = 'maintenance-background';
|
|
|
|
$attributes['class'] = $classes;
|
|
|
|
|
2014-10-08 11:49:20 +00:00
|
|
|
// Seven has custom styling for the maintenance page.
|
|
|
|
$variables['#attached']['library'][] = 'seven/maintenance-page';
|
2012-12-29 08:52:15 +00:00
|
|
|
}
|
2013-02-09 00:13:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_form_BASE_FORM_ID_alter().
|
|
|
|
*
|
|
|
|
* Changes vertical tabs to container and adds meta information.
|
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
2014-02-03 16:02:31 +00:00
|
|
|
/** @var \Drupal\node\NodeInterface $node */
|
2014-08-26 05:24:55 +00:00
|
|
|
$node = $form_state->getFormObject()->getEntity();
|
2013-02-09 00:13:30 +00:00
|
|
|
|
2013-02-16 18:33:45 +00:00
|
|
|
$form['#theme'] = array('node_edit_form');
|
2014-07-11 10:07:19 +00:00
|
|
|
$form['#attached']['css'][] = drupal_get_path('module', 'node') . '/css/node.module.css';
|
2013-02-16 18:33:45 +00:00
|
|
|
|
2013-02-09 00:13:30 +00:00
|
|
|
$form['advanced']['#type'] = 'container';
|
2014-07-02 18:52:48 +00:00
|
|
|
$is_new = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet');
|
2014-06-09 23:20:35 +00:00
|
|
|
$form['meta'] = array(
|
2013-02-09 00:13:30 +00:00
|
|
|
'#attributes' => array('class' => array('entity-meta-header')),
|
|
|
|
'#type' => 'container',
|
|
|
|
'#group' => 'advanced',
|
|
|
|
'#weight' => -100,
|
|
|
|
'published' => array(
|
|
|
|
'#type' => 'item',
|
|
|
|
'#wrapper_attributes' => array('class' => array('published')),
|
2013-08-16 17:13:11 +00:00
|
|
|
'#markup' => $node->isPublished() ? t('Published') : t('Not published'),
|
2013-07-20 12:21:43 +00:00
|
|
|
'#access' => !$node->isNew(),
|
2013-02-09 00:13:30 +00:00
|
|
|
),
|
|
|
|
'changed' => array(
|
|
|
|
'#type' => 'item',
|
|
|
|
'#wrapper_attributes' => array('class' => array('changed', 'container-inline')),
|
2014-07-02 18:52:48 +00:00
|
|
|
'#markup' => '<h4 class="label inline">' . t('Last saved') . '</h4> ' . $is_new,
|
2013-02-09 00:13:30 +00:00
|
|
|
),
|
|
|
|
'author' => array(
|
|
|
|
'#type' => 'item',
|
|
|
|
'#wrapper_attributes' => array('class' => array('author', 'container-inline')),
|
2014-07-02 18:52:48 +00:00
|
|
|
'#markup' => '<h4 class="label inline">' . t('Author') . '</h4> ' . $node->getOwner()->getUsername(),
|
2013-02-09 00:13:30 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
$form['revision_information']['#type'] = 'container';
|
|
|
|
$form['revision_information']['#group'] = 'meta';
|
|
|
|
}
|
2014-10-15 10:05:01 +00:00
|
|
|
|
|
|
|
function seven_preprocess_html(&$variables) {
|
|
|
|
// If on a node add or edit page, add a node-layout class.
|
|
|
|
$path_args = explode('/', \Drupal::request()->getPathInfo());
|
|
|
|
if ($suggestions = theme_get_suggestions($path_args, 'page', '-')) {
|
|
|
|
foreach ($suggestions as $suggestion) {
|
|
|
|
if ($suggestion === 'page-node-edit' || strpos($suggestion, 'page-node-add') !== FALSE) {
|
|
|
|
$variables['attributes']['class'][] = drupal_html_class('node-form-layout');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|