2010-07-06 05:25:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2012-04-19 15:30:31 +00:00
|
|
|
* @file
|
|
|
|
* Functions to support theming in the Bartik theme.
|
|
|
|
*/
|
|
|
|
|
2015-03-29 22:13:25 +00:00
|
|
|
use Drupal\Component\Utility\SafeMarkup;
|
2014-04-07 15:01:20 +00:00
|
|
|
use Drupal\Component\Utility\Xss;
|
Issue #1987398 by Nigel_S, Tim Bozeman, InternetDevels, adsw12, joelpittet, Cottser, mdrummond, dsayswhat, jerdavis, rteijeiro, LewisNyman, Rumato, gnuget: Field.module - Convert theme_ functions to Twig.
2014-03-24 18:15:19 +00:00
|
|
|
use Drupal\Core\Template\Attribute;
|
2013-10-02 21:34:56 +00:00
|
|
|
|
2012-04-19 15:30:31 +00:00
|
|
|
/**
|
2014-11-14 10:43:20 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for HTML document templates.
|
2012-04-19 15:30:31 +00:00
|
|
|
*
|
|
|
|
* Adds body classes if certain regions have content.
|
2010-07-06 05:25:51 +00:00
|
|
|
*/
|
2014-11-14 10:43:20 +00:00
|
|
|
function bartik_preprocess_html(&$variables) {
|
2013-10-21 09:26:54 +00:00
|
|
|
// Add information about the number of sidebars.
|
|
|
|
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
|
2014-11-14 10:43:20 +00:00
|
|
|
$variables['attributes']['class'][] = 'layout-two-sidebars';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
elseif (!empty($variables['page']['sidebar_first'])) {
|
2014-11-14 10:43:20 +00:00
|
|
|
$variables['attributes']['class'][] = 'layout-one-sidebar';
|
|
|
|
$variables['attributes']['class'][] = 'layout-sidebar-first';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
elseif (!empty($variables['page']['sidebar_second'])) {
|
2014-11-14 10:43:20 +00:00
|
|
|
$variables['attributes']['class'][] = 'layout-one-sidebar';
|
|
|
|
$variables['attributes']['class'][] = 'layout-sidebar-second';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-11-14 10:43:20 +00:00
|
|
|
$variables['attributes']['class'][] = 'layout-no-sidebars';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
|
Issue #1164784 by emma.maria, kattekrab, tadityar, DickJohnson, vermario, luco, Jeff Burnz, davidhernandez, David_Rothstein, webchick, Bojhan, LewisNyman, alexpott: “Triptych” term is not widely understood; add "Featured top" and "Featured bottom"
2015-02-06 07:21:55 +00:00
|
|
|
if (!empty($variables['page']['featured_top'])) {
|
2015-02-26 05:41:43 +00:00
|
|
|
$variables['attributes']['class'][] = 'has-featured-top';
|
2010-07-06 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 10:43:20 +00:00
|
|
|
}
|
2010-07-06 05:25:51 +00:00
|
|
|
|
2014-11-14 10:43:20 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK() for page templates.
|
|
|
|
*/
|
|
|
|
function bartik_preprocess_page(&$variables) {
|
2014-02-11 11:18:12 +00:00
|
|
|
// Set the options that apply to both page and maintenance page.
|
|
|
|
_bartik_process_page($variables);
|
|
|
|
|
2010-07-06 05:25:51 +00:00
|
|
|
// Since the title and the shortcut link are both block level elements,
|
|
|
|
// positioning them next to each other is much simpler with a wrapper div.
|
|
|
|
if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
|
2014-04-08 22:28:50 +00:00
|
|
|
// Add a wrapper div using the title_prefix and title_suffix render
|
|
|
|
// elements.
|
2010-07-06 05:25:51 +00:00
|
|
|
$variables['title_prefix']['shortcut_wrapper'] = array(
|
|
|
|
'#markup' => '<div class="shortcut-wrapper clearfix">',
|
|
|
|
'#weight' => 100,
|
|
|
|
);
|
|
|
|
$variables['title_suffix']['shortcut_wrapper'] = array(
|
|
|
|
'#markup' => '</div>',
|
|
|
|
'#weight' => -99,
|
|
|
|
);
|
|
|
|
// Make sure the shortcut link is the first item in title_suffix.
|
|
|
|
$variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-11 22:06:40 +00:00
|
|
|
/**
|
2014-04-08 22:28:50 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
|
2010-07-11 22:06:40 +00:00
|
|
|
*/
|
|
|
|
function bartik_preprocess_maintenance_page(&$variables) {
|
2012-02-08 11:05:27 +00:00
|
|
|
// By default, site_name is set to Drupal if no db connection is available
|
|
|
|
// or during site installation. Setting site_name to an empty string makes
|
|
|
|
// the site and update pages look cleaner.
|
|
|
|
// @see template_preprocess_maintenance_page
|
2010-11-26 11:00:37 +00:00
|
|
|
if (!$variables['db_is_active']) {
|
2012-02-08 11:05:27 +00:00
|
|
|
$variables['site_name'] = '';
|
2010-11-26 11:00:37 +00:00
|
|
|
}
|
2014-10-08 11:49:20 +00:00
|
|
|
|
|
|
|
// Bartik has custom styling for the maintenance page.
|
|
|
|
$variables['#attached']['library'][] = 'bartik/maintenance_page';
|
2013-10-02 21:34:56 +00:00
|
|
|
|
2014-02-11 11:18:12 +00:00
|
|
|
// Set the options that apply to both page and maintenance page.
|
|
|
|
_bartik_process_page($variables);
|
2010-07-06 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 17:40:10 +00:00
|
|
|
/**
|
2014-04-08 22:28:50 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for node.html.twig.
|
2013-05-24 17:40:10 +00:00
|
|
|
*/
|
|
|
|
function bartik_preprocess_node(&$variables) {
|
|
|
|
// Remove the "Add new comment" link on teasers or when the comment form is
|
|
|
|
// displayed on the page.
|
|
|
|
if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) {
|
|
|
|
unset($variables['content']['links']['comment']['#links']['comment-add']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 16:38:08 +00:00
|
|
|
/**
|
2014-04-08 22:28:50 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for block.html.twig.
|
2014-03-03 16:38:08 +00:00
|
|
|
*/
|
|
|
|
function bartik_preprocess_block(&$variables) {
|
|
|
|
// Add a clearfix class to system branding blocks.
|
|
|
|
if ($variables['plugin_id'] == 'system_branding_block') {
|
|
|
|
$variables['attributes']['class'][] = 'clearfix';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-20 10:02:55 +00:00
|
|
|
/**
|
2014-09-27 07:28:57 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for menu.html.twig.
|
2010-11-20 10:02:55 +00:00
|
|
|
*/
|
2014-09-27 07:28:57 +00:00
|
|
|
function bartik_preprocess_menu(&$variables) {
|
2014-07-30 12:04:04 +00:00
|
|
|
$variables['attributes']['class'][] = 'clearfix';
|
2010-11-20 10:02:55 +00:00
|
|
|
}
|
2010-12-06 19:34:33 +00:00
|
|
|
|
2014-02-11 11:18:12 +00:00
|
|
|
/**
|
2014-03-08 10:40:02 +00:00
|
|
|
* Helper function for handling the site name and slogan.
|
|
|
|
*/
|
2014-02-11 11:18:12 +00:00
|
|
|
function _bartik_process_page(&$variables) {
|
|
|
|
$site_config = \Drupal::config('system.site');
|
|
|
|
// Always print the site name and slogan, but if they are toggled off, we'll
|
|
|
|
// just hide them visually.
|
|
|
|
$variables['hide_site_name'] = theme_get_setting('features.name') ? FALSE : TRUE;
|
|
|
|
$variables['hide_site_slogan'] = theme_get_setting('features.slogan') ? FALSE : TRUE;
|
|
|
|
if ($variables['hide_site_name']) {
|
|
|
|
// If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
|
2015-03-29 22:13:25 +00:00
|
|
|
$variables['site_name'] = SafeMarkup::checkPlain($site_config->get('name'));
|
2014-02-11 11:18:12 +00:00
|
|
|
}
|
|
|
|
if ($variables['hide_site_slogan']) {
|
2014-04-08 22:28:50 +00:00
|
|
|
// If toggle_site_slogan is FALSE, the site_slogan will be empty, so we
|
|
|
|
// rebuild it.
|
2014-04-07 15:01:20 +00:00
|
|
|
$variables['site_slogan'] = Xss::filterAdmin($site_config->get('slogan'));
|
2014-02-11 11:18:12 +00:00
|
|
|
}
|
|
|
|
}
|