extremely important to turn off this feature on production websites.', array('!link' => url('admin/appearance/settings/' . $GLOBALS['theme']))), 'warning', false);
}
// hook_theme() expects an array, so return an empty one.
return array();
}
/**
* Return a themed breadcrumb trail.
*
* @param $variables
* - title: An optional string to be used as a navigational heading to give
* context for breadcrumb links to screen-reader users.
* - title_attributes_array: Array of HTML attributes for the title. It is
* flattened into a string within the theme function.
* - breadcrumb: An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function direction_css_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
$output = '';
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('direction_css_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('direction_css_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
// Return the breadcrumb with separators.
if (!empty($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('direction_css_breadcrumb_separator');
$trailing_separator = $title = '';
if (theme_get_setting('direction_css_breadcrumb_title')) {
$item = menu_get_item();
if (!empty($item['tab_parent'])) {
// If we are on a non-default tab, use the tab's title.
$breadcrumb[] = check_plain($item['title']);
}
else {
$breadcrumb[] = drupal_get_title();
}
}
elseif (theme_get_setting('direction_css_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users.
if (empty($variables['title'])) {
$variables['title'] = t('You are here');
}
// Unless overridden by a preprocess function, make the heading invisible.
if (!isset($variables['title_attributes_array']['class'])) {
$variables['title_attributes_array']['class'][] = 'breadcrumb__title element-invisible';
}
if (!empty($breadcrumb_separator)) {
$breadcrumb_separator = ''.$breadcrumb_separator.'';
}
if (!empty($trailing_separator)) {
$trailing_separator = ''.$trailing_separator.'';
}
// Build the breadcrumb trail.
$li = '
';
$output = '
' . $li, $breadcrumb) . $trailing_separator . '';
$output .= '';
}
}
return $output;
}
/**
* Override or insert variables into the html template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered. This is usually "html", but can
* also be "maintenance_page" since direction_css_preprocess_maintenance_page() calls
* this function to have consistent variables.
*/
function direction_css_preprocess_html(&$variables, $hook) {
// Add variables and paths needed for HTML5 and responsive support.
$variables['base_path'] = base_path();
$variables['path_to_direction_css'] = drupal_get_path('theme', 'direction_css');
$variables['path_to_direction_css_framework'] = $variables['path_to_direction_css'].'/framework/direction-css';
$variables['add_html5_shim'] = (bool) theme_get_setting('direction_css_html_html5shiv');
$variables['add_browserjs'] = (bool) theme_get_setting('direction_css_html_browserjs');
$variables['default_mobile_metatags'] = (bool) theme_get_setting('direction_css_html_mobile');
$variables['mobile_viewport'] = theme_get_setting('direction_css_html_mobile_viewport');
$variables['head_scripts'] = drupal_get_js('head');
$variables['before_content_scripts'] = drupal_get_js('before_content');
$variables['before_content_html'] = direction_css_get_before_content_html();
if ($variables['add_browserjs']) {
drupal_add_js($variables['path_to_direction_css_framework'] . '/js/browser.js', array('group' => JS_THEME));
}
drupal_add_js('jQuery(function($){ $("html").removeClass("no-js"); })', 'inline');
// If the user is silly and enables direction_css as the theme, add some styles.
// if ($GLOBALS['theme'] == 'direction_css') {
// add default styles (ex. reset)
// }
// Attributes for html element.
$variables['html_attributes_array'] = array(
'lang' => $variables['language']->language,
'dir' => $variables['language']->dir,
);
// Send X-UA-Compatible HTTP header to force IE to use the most recent
// rendering engine or use Chrome's frame rendering engine if available.
// This also prevents the IE compatibility mode button to appear when using
// conditional classes on the html tag.
if (is_null(drupal_get_http_header('X-UA-Compatible'))) {
drupal_add_http_header('X-UA-Compatible', 'IE=edge,chrome=1');
}
$variables['classes_array'][] = 'page';
// Return early, so the maintenance page does not call any of the code below.
if ($hook != 'html') {
return;
}
foreach ($variables['classes_array'] as $i => $class) {
if (strpos($class, 'node-type-') === 0) {
$variables['classes_array'][$i] = 'page-'.$class;
break;
}
}
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
if (!$variables['is_front']) {
$variables['classes_array'][] = 'page-inner';
// todo: leave 'front' class for compatibility?
direction_css_remove_class($variables['classes_array'], 'not-front');
}
else {
$variables['classes_array'][] = 'page-front';
// todo: leave 'front' class for compatibility?
direction_css_remove_class($variables['classes_array'], 'front');
}
// Add unique class for each page.
$variables['classes_array'][] = drupal_html_class('page-id-' . $_GET['q']);
// Store the menu item since it has some useful information.
$variables['menu_item'] = menu_get_item();
if ($variables['menu_item']) {
switch ($variables['menu_item']['page_callback']) {
case 'views_page':
// Is this a Views page?
$variables['classes_array'][] = 'page-views';
break;
case 'page_manager_page_execute':
case 'page_manager_node_view':
case 'page_manager_contact_site':
// Is this a Panels page?
$variables['classes_array'][] = 'page-panels';
break;
}
}
// Serialize RDF Namespaces into an RDFa 1.1 prefix attribute.
if ($variables['rdf_namespaces']) {
$prefixes = array();
foreach (explode("\n ", ltrim($variables['rdf_namespaces'])) as $namespace) {
// Remove xlmns: and ending quote and fix prefix formatting.
$prefixes[] = str_replace('="', ': ', substr($namespace, 6, -1));
}
$variables['rdf_namespaces'] = ' prefix="' . implode(' ', $prefixes) . '"';
}
}
/**
* Override or insert variables into the html templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("html" in this case.)
*/
function direction_css_process_html(&$variables, $hook) {
// Flatten out html_attributes.
$variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']);
}
/**
* Override or insert variables in the html_tag theme function.
*/
function direction_css_process_html_tag(&$variables) {
$tag = &$variables['element'];
if ($tag['#tag'] == 'style' || $tag['#tag'] == 'script') {
// Remove redundant type attribute and CDATA comments.
unset($tag['#attributes']['type'], $tag['#value_prefix'], $tag['#value_suffix']);
// Remove media="all" but leave others unaffected.
if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') {
unset($tag['#attributes']['media']);
}
}
}
/**
* Implement hook_html_head_alter().
*/
function direction_css_html_head_alter(&$head) {
// Simplify the meta tag for character encoding.
if (isset($head['system_meta_content_type']['#attributes']['content'])) {
$head['system_meta_content_type']['#attributes'] = array('charset' => str_replace('text/html; charset=', '', $head['system_meta_content_type']['#attributes']['content']));
}
}
/**
* Override or insert variables into the page template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("page" in this case.)
*/
function direction_css_preprocess_page(&$variables, $hook) {
$variables['grid_columns'] = theme_get_setting('direction_css_grid_columns');
$variables['grid_sidebar_left_width'] = theme_get_setting('direction_css_grid_sidebar_left_width');
$variables['grid_sidebar_left_offset'] = theme_get_setting('direction_css_grid_sidebar_left_offset');
$variables['grid_sidebar_right_width'] = theme_get_setting('direction_css_grid_sidebar_right_width');
$variables['grid_sidebar_right_offset'] = theme_get_setting('direction_css_grid_sidebar_right_offset');
}
/**
* Override or insert variables into the maintenance page template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("maintenance_page" in this case.)
*/
function direction_css_preprocess_maintenance_page(&$variables, $hook) {
direction_css_preprocess_html($variables, $hook);
// There's nothing maintenance-related in direction_css_preprocess_page(). Yet.
//direction_css_preprocess_page($variables, $hook);
}
/**
* Override or insert variables into the maintenance page template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("maintenance_page" in this case.)
*/
function direction_css_process_maintenance_page(&$variables, $hook) {
direction_css_process_html($variables, $hook);
// Ensure default regions get a variable. Theme authors often forget to remove
// a deleted region's variable in maintenance-page.tpl.
foreach (array('header', 'highlighted', 'help', 'content', 'content_top', 'content_bottom', 'sidebar_first', 'sidebar_second', 'footer', 'bottom') as $region) {
if (!isset($variables[$region])) {
$variables[$region] = '';
}
}
}
/**
* Override or insert variables into the node templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*/
function direction_css_preprocess_node(&$variables, $hook) {
// Add $unpublished variable.
$variables['unpublished'] = (!$variables['status']) ? true : false;
// Add pubdate to submitted variable.
$variables['pubdate'] = '';
if ($variables['display_submitted']) {
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['pubdate']));
}
// Add a class for the view mode.
if (!$variables['teaser']) {
$variables['classes_array'][] = 'node-view-' . $variables['view_mode'];
}
// Add a class for the view mode.
if ($variables['page']) {
$variables['classes_array'][] = 'node-view-page';
}
// Add a class to show node is authored by current user.
if ($variables['uid'] && $variables['uid'] == $GLOBALS['user']->uid) {
$variables['classes_array'][] = 'node-by-viewer';
}
//direction_css_remove_class($variables['classes_array'], 'clearfix');
$variables['title_attributes_array']['class'][] = 'node-title';
}
/**
* Override or insert variables into the comment templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("comment" in this case.)
*/
function direction_css_preprocess_comment(&$variables, $hook) {
// If comment subjects are disabled, don't display them.
if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) {
$variables['title'] = '';
}
// Add pubdate to submitted variable.
$variables['pubdate'] = '';
$variables['submitted'] = t('!username replied on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['pubdate']));
// Zebra striping.
if ($variables['id'] == 1) {
$variables['classes_array'][] = 'first';
}
if ($variables['id'] == $variables['node']->comment_count) {
$variables['classes_array'][] = 'last';
}
$variables['classes_array'][] = $variables['zebra'];
$variables['title_attributes_array']['class'][] = 'comment-title';
}
/**
* Preprocess variables for region.tpl.php
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("region" in this case.)
*/
function direction_css_preprocess_region(&$variables, $hook) {
// Sidebar regions get some extra classes and a common template suggestion.
if (strpos($variables['region'], 'sidebar_') === 0) {
if ($variables['region'] === 'sidebar_first') {
direction_css_remove_class($variables['classes_array'], 'region-sidebar-first');
$variables['classes_array'][] = 'region-sidebar-left';
}
else if ($variables['region'] === 'sidebar_second') {
direction_css_remove_class($variables['classes_array'], 'region-sidebar-second');
$variables['classes_array'][] = 'region-sidebar-right';
}
// Allow a region-specific template to override direction_css's region--sidebar.
array_unshift($variables['theme_hook_suggestions'], 'region__sidebar');
}
elseif ($variables['region'] == 'content') {
direction_css_remove_class($variables['classes_array'], 'region');
direction_css_remove_class($variables['classes_array'], 'region-content');
$variables['classes_array'][] = 'page__content';
}
elseif ($variables['region'] == 'content_top') {
direction_css_remove_class($variables['classes_array'], 'region');
direction_css_remove_class($variables['classes_array'], 'region-content-top');
$variables['classes_array'][] = 'page__content__before';
}
elseif ($variables['region'] == 'content') {
direction_css_remove_class($variables['classes_array'], 'region');
direction_css_remove_class($variables['classes_array'], 'region-content-bottom');
$variables['classes_array'][] = 'page__content__after';
}
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function direction_css_preprocess_block(&$variables, $hook) {
// Use a template with no wrapper for the page's main content.
if ($variables['block_html_id'] == 'block-system-main') {
$variables['theme_hook_suggestions'][] = 'block__no_wrapper';
}
// Classes describing the position of the block within the region.
if ($variables['block_id'] == 1) {
$variables['classes_array'][] = 'first';
}
// The last_in_region property is set in direction_css_page_alter().
if (isset($variables['block']->last_in_region)) {
$variables['classes_array'][] = 'last';
}
$variables['classes_array'][] = $variables['block_zebra'];
$variables['classes_array'][] = $variables['block_html_id'];
$variables['title_attributes_array']['class'][] = 'block__title';
// Add Aria Roles via attributes.
switch ($variables['block']->module) {
case 'system':
switch ($variables['block']->delta) {
case 'main':
// Note: the "main" role goes in the page.tpl, not here.
break;
case 'help':
case 'powered-by':
$variables['attributes_array']['role'] = 'complementary';
break;
default:
// Any other "system" block is a menu block.
$variables['attributes_array']['role'] = 'navigation';
break;
}
break;
case 'menu':
case 'menu_block':
case 'blog':
case 'book':
case 'comment':
case 'forum':
case 'shortcut':
case 'statistics':
$variables['attributes_array']['role'] = 'navigation';
break;
case 'search':
$variables['attributes_array']['role'] = 'search';
break;
case 'help':
case 'aggregator':
case 'locale':
case 'poll':
case 'profile':
$variables['attributes_array']['role'] = 'complementary';
break;
case 'node':
switch ($variables['block']->delta) {
case 'syndicate':
$variables['attributes_array']['role'] = 'complementary';
break;
case 'recent':
$variables['attributes_array']['role'] = 'navigation';
break;
}
break;
case 'user':
switch ($variables['block']->delta) {
case 'login':
$variables['attributes_array']['role'] = 'form';
break;
case 'new':
case 'online':
$variables['attributes_array']['role'] = 'complementary';
break;
}
break;
}
// Bean support
if (isset($variables['elements']['bean'])) {
$bean = reset($variables['elements']['bean']);
if (isset($bean['#entity'])) {
$bean = $bean['#entity'];
$variables['bean'] = $bean;
$variables['classes_array'][] = 'bean-' . drupal_html_class($bean->type) . '__block';
}
}
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function direction_css_process_block(&$variables, $hook) {
// Drupal 7 should use a $title variable instead of $block->subject.
$variables['title'] = $variables['block']->subject;
}
/**
* Implements hook_page_alter().
*
* Look for the last block in the region. This is impossible to determine from
* within a preprocess_block function.
*
* @param $page
* Nested array of renderable elements that make up the page.
*/
function direction_css_page_alter(&$page) {
// Look in each visible region for blocks.
foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) {
if (!empty($page[$region])) {
// Find the last block in the region.
$blocks = array_reverse(element_children($page[$region]));
while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) {
array_shift($blocks);
}
if ($blocks) {
$page[$region][$blocks[0]]['#block']->last_in_region = true;
}
}
}
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*
* Prevent user-facing field styling from screwing up node edit forms by
* renaming the classes on the node edit form's field wrappers.
*/
function direction_css_form_node_form_alter(&$form, &$form_state, $form_id) {
// Remove if #1245218 is backported to D7 core.
foreach (array_keys($form) as $item) {
if (strpos($item, 'field_') === 0) {
if (!empty($form[$item]['#attributes']['class'])) {
foreach ($form[$item]['#attributes']['class'] as &$class) {
if (strpos($class, 'field-type-') === 0 || strpos($class, 'field-name-') === 0) {
// Make the class different from that used in theme_field().
$class = 'form-' . $class;
}
}
}
}
}
}
/**
* Override or insert variables into the field templates.
*
* @param $variables
* An array of variables to pass to the theme template.
*/
function direction_css_preprocess_field(&$variables) {
$element =& $variables['element'];
// default alt text
if ($element['#field_type'] === 'image') {
foreach ($variables['items'] as $i => $item) {
if (empty($item['alt'])) {
$alt = '';
if (!empty($item['title'])) {
$alt = $item['title'];
}
else if (isset($element['#object']->title)) {
$alt = $element['#object']->title;
}
$variables['items'][$i]['#item']['alt'] = $alt;
}
}
}
}
/**
* Implements hook_menu_local_tasks().
*/
function direction_css_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '