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.
|
|
|
|
*/
|
|
|
|
|
2013-10-02 21:34:56 +00:00
|
|
|
use Drupal\Core\Template\RenderWrapper;
|
|
|
|
|
2012-04-19 15:30:31 +00:00
|
|
|
/**
|
2014-01-01 20:32:52 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for page 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-01-01 20:32:52 +00:00
|
|
|
function bartik_preprocess_page(&$variables) {
|
2013-10-21 09:26:54 +00:00
|
|
|
// Add information about the number of sidebars.
|
2014-01-01 20:32:52 +00:00
|
|
|
/** @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
|
|
|
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'two-sidebars';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
elseif (!empty($variables['page']['sidebar_first'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'one-sidebar';
|
|
|
|
$classes[] = 'sidebar-first';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
elseif (!empty($variables['page']['sidebar_second'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'one-sidebar';
|
|
|
|
$classes[] = 'sidebar-second';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'no-sidebars';
|
2013-10-21 09:26:54 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 05:25:51 +00:00
|
|
|
if (!empty($variables['page']['featured'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'featured';
|
2010-07-06 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($variables['page']['triptych_first'])
|
|
|
|
|| !empty($variables['page']['triptych_middle'])
|
|
|
|
|| !empty($variables['page']['triptych_last'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'triptych';
|
2010-07-06 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($variables['page']['footer_firstcolumn'])
|
|
|
|
|| !empty($variables['page']['footer_secondcolumn'])
|
|
|
|
|| !empty($variables['page']['footer_thirdcolumn'])
|
|
|
|
|| !empty($variables['page']['footer_fourthcolumn'])) {
|
2014-01-01 20:32:52 +00:00
|
|
|
$classes[] = 'footer-columns';
|
2010-07-06 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-01 20:32:52 +00:00
|
|
|
// Store back the classes to the htmlpage object.
|
|
|
|
$attributes['class'] = $classes;
|
|
|
|
|
2013-05-24 16:46:19 +00:00
|
|
|
// Pass the main menu and secondary menu to the template as render arrays.
|
|
|
|
if (!empty($variables['main_menu'])) {
|
|
|
|
$variables['main_menu']['#attributes']['id'] = 'main-menu-links';
|
|
|
|
$variables['main_menu']['#attributes']['class'] = array('links', 'clearfix');
|
|
|
|
}
|
|
|
|
if (!empty($variables['secondary_menu'])) {
|
|
|
|
$variables['secondary_menu']['#attributes']['id'] = 'secondary-menu-links';
|
2013-08-05 22:52:22 +00:00
|
|
|
$variables['secondary_menu']['#attributes']['class'] = array('links', 'inline', 'clearfix');
|
2013-05-24 16:46:19 +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
|
|
|
// 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']) {
|
|
|
|
// Add a wrapper div using the title_prefix and title_suffix render elements.
|
|
|
|
$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
|
|
|
/**
|
2013-10-03 20:55:34 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for maintenance page templates.
|
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
|
|
|
}
|
2013-10-02 21:34:56 +00:00
|
|
|
$variables['styles'] = new RenderWrapper('drupal_get_css');
|
|
|
|
// Normally we could attach libraries via hook_page_alter(), but when the
|
|
|
|
// database is inactive it's not called so we add them here.
|
|
|
|
$libraries = array(
|
|
|
|
'#attached' => array(
|
|
|
|
'library' => array(
|
2014-03-09 19:59:45 +00:00
|
|
|
'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
|
|
|
/**
|
2013-10-03 20:55:34 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for node templates.
|
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
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK() for block templates.
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Implements theme_menu_tree().
|
|
|
|
*/
|
|
|
|
function bartik_menu_tree($variables) {
|
|
|
|
return '<ul class="menu clearfix">' . $variables['tree'] . '</ul>';
|
|
|
|
}
|
2010-12-06 19:34:33 +00:00
|
|
|
|
2013-07-24 20:09:12 +00:00
|
|
|
/**
|
|
|
|
* Implements theme_menu_tree__shortcut_default() {
|
|
|
|
*/
|
|
|
|
function bartik_menu_tree__shortcut_default($variables) {
|
|
|
|
return '<ul class="menu">' . $variables['tree'] . '</ul>';
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:34:33 +00:00
|
|
|
/**
|
|
|
|
* Implements theme_field__field_type().
|
|
|
|
*/
|
|
|
|
function bartik_field__taxonomy_term_reference($variables) {
|
|
|
|
$output = '';
|
|
|
|
|
2013-11-05 17:19:50 +00:00
|
|
|
// Render the label either as a visible list or make it visually hidden for accessibility.
|
|
|
|
$hidden_class = empty($variables['label_hidden']) ? '' : ' visually-hidden';
|
|
|
|
$output .= '<h3 class="field-label' . $hidden_class . '">' . $variables['label'] . ': </h3>';
|
2010-12-06 19:34:33 +00:00
|
|
|
|
|
|
|
// Render the items.
|
|
|
|
$output .= ($variables['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="links">';
|
|
|
|
foreach ($variables['items'] as $delta => $item) {
|
2010-12-14 01:04:27 +00:00
|
|
|
$output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
|
2010-12-06 19:34:33 +00:00
|
|
|
}
|
|
|
|
$output .= '</ul>';
|
|
|
|
|
|
|
|
// Render the top-level DIV.
|
2012-08-03 15:31:18 +00:00
|
|
|
$variables['attributes']['class'][] = 'clearfix';
|
|
|
|
$output = '<div ' . $variables['attributes'] . '>' . $output . '</div>';
|
2010-12-06 19:34:33 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
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.
|
|
|
|
$variables['site_name'] = check_plain($site_config->get('name'));
|
|
|
|
}
|
|
|
|
if ($variables['hide_site_slogan']) {
|
|
|
|
// If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
|
|
|
|
$variables['site_slogan'] = filter_xss_admin($site_config->get('slogan'));
|
|
|
|
}
|
|
|
|
}
|