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-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-11-14 10:43:20 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for HTML document templates.
|
2013-10-21 09:26:54 +00:00
|
|
|
*/
|
2014-11-14 10:43:20 +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) {
|
2014-12-12 09:08:12 +00:00
|
|
|
$variables['attributes']['class'][] = 'node-form-layout';
|
2014-11-14 10:43:20 +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'])) {
|
2015-01-12 21:28:44 +00:00
|
|
|
/** @var \Drupal\node\NodeTypeInterface $type */
|
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
|
|
|
foreach ($variables['content'] as $type) {
|
2015-08-27 14:42:23 +00:00
|
|
|
$variables['types'][$type->id()]['label'] = $type->label();
|
2015-01-12 21:28:44 +00:00
|
|
|
$variables['types'][$type->id()]['url'] = \Drupal::url('node.add', array('node_type' => $type->id()));
|
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
|
2015-07-11 08:10:48 +00:00
|
|
|
* separate variables for the label 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) {
|
2015-08-27 14:42:23 +00:00
|
|
|
$variables['types'][$type->id()]['label'] = $type->label();
|
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
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Issue #2487025 by shellshocked59, harings_rob, rteijeiro, subhojit777, vijaycs85, ashutoshsngh, aburrows, swetashahi, mradcliffe, Wim Leers, lauriii, LewisNyman, Bojhan, DeeLay, B_man, davidhernandez, lizzjoy, lweinmeister, wizonesolutions, arh1, GenerUmali, tstoeckler: Remove contextual links in Seven
2015-10-05 05:45:06 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_block() for block content.
|
|
|
|
*
|
|
|
|
* Disables contextual links for all blocks.
|
|
|
|
*/
|
|
|
|
function seven_preprocess_block(&$variables) {
|
|
|
|
if (isset($variables['title_suffix']['contextual_links'])) {
|
|
|
|
unset($variables['title_suffix']['contextual_links']);
|
|
|
|
unset($variables['elements']['#contextual_links']);
|
|
|
|
|
|
|
|
$variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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-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
|
|
|
|
|
|
|
/**
|
2016-05-06 12:54:45 +00:00
|
|
|
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
|
2013-02-09 00:13:30 +00:00
|
|
|
*
|
|
|
|
* 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-11-26 10:37:53 +00:00
|
|
|
$form['#attached']['library'][] = 'seven/node-form';
|
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(
|
2015-06-12 15:08:24 +00:00
|
|
|
'#attributes' => array('class' => array('entity-meta__header')),
|
2013-02-09 00:13:30 +00:00
|
|
|
'#type' => 'container',
|
|
|
|
'#group' => 'advanced',
|
|
|
|
'#weight' => -100,
|
|
|
|
'published' => array(
|
2015-06-12 15:08:24 +00:00
|
|
|
'#type' => 'html_tag',
|
|
|
|
'#tag' => 'h3',
|
|
|
|
'#value' => $node->isPublished() ? t('Published') : t('Not published'),
|
2013-07-20 12:21:43 +00:00
|
|
|
'#access' => !$node->isNew(),
|
2015-06-12 15:08:24 +00:00
|
|
|
'#attributes' => array(
|
2016-10-19 13:03:36 +00:00
|
|
|
'class' => ['entity-meta__title'],
|
2015-06-12 15:08:24 +00:00
|
|
|
),
|
2013-02-09 00:13:30 +00:00
|
|
|
),
|
|
|
|
'changed' => array(
|
|
|
|
'#type' => 'item',
|
2015-06-12 15:08:24 +00:00
|
|
|
'#wrapper_attributes' => array('class' => array('entity-meta__last-saved', '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';
|
|
|
|
}
|