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.
*/
2013-07-14 20:17:23 +00:00
use Drupal\Core\Template\RenderWrapper;
2014-02-08 20:57:42 +00:00
use Drupal\Component\Utility\String;
2013-07-14 20:17:23 +00:00
2013-08-30 15:22:28 +00:00
/**
* Implements hook_library_info().
*/
function seven_library_info() {
$path = drupal_get_path('theme', 'seven');
$libraries['install-page'] = array(
2013-09-21 15:23:51 +00:00
'version' => \Drupal::VERSION,
2013-08-30 15:22:28 +00:00
'js' => array(
$path . '/js/mobile.install.js' => array(
'group' => JS_THEME,
),
),
'css' => array(
$path . '/install-page.css' => array(
'group' => CSS_AGGREGATE_THEME,
),
),
);
2014-02-08 20:57:42 +00:00
$libraries['drupal.nav-tabs'] = array(
'version' => \Drupal::VERSION,
'js' => array(
drupal_get_path('theme', 'seven') . '/js/nav-tabs.js' => array('group' => JS_THEME),
),
'dependencies' => array(
array('system', 'matchmedia'),
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'jquery.once'),
array('system', 'jquery.intrinsic'),
),
);
2013-08-30 15:22:28 +00:00
return $libraries;
}
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-01-01 20:32:52 +00:00
$classes[] = 'one-sidebar';
$classes[] = 'sidebar-first';
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
}
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
/**
* Overrides theme_menu_local_tasks().
*
* Returns HTML for primary and secondary local tasks.
*
**/
function seven_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#attached'] = array(
'library' => array(
array('seven', 'drupal.nav-tabs'),
),
);
$variables['primary']['#prefix'] = '<h2 id="primary-tabs-title" class="visually-hidden">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<nav role="navigation" class="is-horizontal is-collapsible" aria-labelledby="primary-tabs-title" data-drupal-nav-tabs>';
$variables['primary']['#prefix'] .= '<button class="reset-appearance tabs__tab tabs__trigger" aria-label="Primary tabs display toggle" data-drupal-nav-tabs-trigger>•••</button>';
$variables['primary']['#prefix'] .= '<ul class="tabs primary clearfix" data-drupal-nav-tabs-target>';
$variables['primary']['#suffix'] = '</ul>';
$variables['primary']['#suffix'] .= '</nav>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#attached'] = array(
'library' => array(
array('seven', 'drupal.nav-tabs'),
),
);
$variables['secondary']['#prefix'] = '<h2 id="secondary-tabs-title" class="visually-hidden">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<nav role="navigation" class="is-horizontal" aria-labelledby="secondary-tabs-title" data-drupal-nav-tabs>';
$variables['secondary']['#prefix'] .= '<ul class="tabs secondary clearfix">';
$variables['secondary']['#suffix'] = '</ul>';
$variables['secondary']['#suffix'] .= '</nav>';
$output .= drupal_render($variables['secondary']);
}
return $output;
}
/**
* Overrides theme_menu_local_task().
*
* Returns HTML for a local task.
*
**/
function seven_menu_local_task($variables) {
$link = $variables['element']['#link'];
$link += array(
'localized_options' => array(),
);
$link_text = $link['title'];
if (!empty($variables['element']['#active'])) {
// Add text to indicate active tab for non-visual users.
$active = '<span class="visually-hidden">' . t('(active tab)') . '</span>';
// If the link does not contain HTML already, String::checkPlain() it now.
// After we set 'html'=TRUE the link will not be sanitized by l().
if (empty($link['localized_options']['html'])) {
$link['title'] = String::checkPlain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
}
if (!empty($link['href'])) {
// @todo - remove this once all pages are converted to routes.
$a_tag = l($link_text, $link['href'], $link['localized_options']);
}
else {
$a_tag = \Drupal::l($link_text, $link['route_name'], $link['route_parameters'], $link['localized_options']);
}
return '<li' . (!empty($variables['element']['#active']) ? ' class="tabs__tab active"' : ' class="tabs__tab"') . '>' . $a_tag . '</li>';
}
2009-07-31 19:35:57 +00:00
/**
2012-04-19 15:30:31 +00:00
* Displays the list of available node types for node creation.
2009-07-31 19:35:57 +00:00
*/
2009-10-09 01:00:08 +00:00
function seven_node_add_list($variables) {
$content = $variables['content'];
2009-07-31 19:35:57 +00:00
if ($content) {
2010-10-03 02:46:12 +00:00
$output = '<ul class="admin-list">';
2012-05-14 02:50:42 +00:00
foreach ($content as $type) {
2009-07-31 19:35:57 +00:00
$output .= '<li class="clearfix">';
2012-11-06 13:42:12 +00:00
$content = '<span class="label">' . check_plain($type->name) . '</span>';
$content .= '<div class="description">' . filter_xss_admin($type->description) . '</div>';
$options['html'] = TRUE;
$output .= l($content, 'node/add/' . $type->type, $options);
2009-07-31 19:35:57 +00:00
$output .= '</li>';
}
$output .= '</ul>';
}
2010-10-03 00:09:28 +00:00
else {
$output = '<p>' . t('You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.', array('@create-content' => url('admin/structure/types/add'))) . '</p>';
}
2009-07-31 19:35:57 +00:00
return $output;
}
2013-02-18 22:17:49 +00:00
/**
* Overrides theme_custom_block_add_list().
*
* Displays the list of available custom block types for creation.
*/
function seven_custom_block_add_list($variables) {
$output = '';
2013-09-12 00:35:09 +00:00
if (!empty($variables['types'])) {
2013-02-18 22:17:49 +00:00
$output = '<ul class="admin-list">';
2013-09-12 00:35:09 +00:00
foreach ($variables['types'] as $id => $type) {
2013-02-18 22:17:49 +00:00
$output .= '<li class="clearfix">';
2013-09-12 00:35:09 +00:00
$content = '<span class="label">' . check_plain($type['title']) . '</span>';
$content .= '<div class="description">' . filter_xss_admin($type['description']) . '</div>';
$options = $type['localized_options'];
2013-02-18 22:17:49 +00:00
$options['html'] = TRUE;
2013-09-21 15:23:51 +00:00
$output .= \Drupal::l($content, 'custom_block.add_form', array('custom_block_type' => $id), $options);
2013-02-18 22:17:49 +00:00
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
2009-07-31 19:35:57 +00:00
/**
2010-10-01 15:24:18 +00:00
* Overrides theme_admin_block_content().
2009-07-31 19:35:57 +00:00
*
2012-04-19 15:30:31 +00:00
* Uses an unordered list markup in both compact and extended mode.
2009-07-31 19:35:57 +00:00
*/
2009-10-09 01:00:08 +00:00
function seven_admin_block_content($variables) {
$content = $variables['content'];
2009-07-31 19:35:57 +00:00
$output = '';
if (!empty($content)) {
$output = system_admin_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
foreach ($content as $item) {
2012-11-06 13:42:12 +00:00
$output .= '<li>';
$content = '<span class="label">' . filter_xss_admin($item['title']) . '</span>';
$options = $item['localized_options'];
$options['html'] = TRUE;
2010-10-01 15:24:18 +00:00
if (isset($item['description']) && !system_admin_compact_mode()) {
2012-11-06 13:42:12 +00:00
$content .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
2009-07-31 19:35:57 +00:00
}
2014-01-29 08:25:00 +00:00
$output .= l($content, $item['link_path'], $options);
2009-07-31 19:35:57 +00:00
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
/**
2012-04-19 15:30:31 +00:00
* Overrides theme_tablesort_indicator().
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
*/
2009-10-09 01:00:08 +00:00
function seven_tablesort_indicator($variables) {
2009-07-31 19:35:57 +00:00
$theme_path = drupal_get_path('theme', 'seven');
2013-06-09 18:08:59 +00:00
2013-11-23 00:23:37 +00:00
if ($variables['style'] == 'asc') {
2013-06-09 18:08:59 +00:00
$image_uri = $theme_path . '/images/arrow-asc.png';
2013-06-18 12:11:49 +00:00
$text = t('Sort ascending');
2009-07-31 19:35:57 +00:00
}
else {
2013-06-09 18:08:59 +00:00
$image_uri = $theme_path . '/images/arrow-desc.png';
2013-06-18 12:11:49 +00:00
$text = t('Sort descending');
2009-07-31 19:35:57 +00:00
}
2013-06-09 18:08:59 +00:00
$image = array(
'#theme' => 'image',
'#uri' => $image_uri,
'#alt' => $text,
2013-07-23 23:31:40 +00:00
'#width' => 9,
'#height' => 5,
2013-06-09 18:08:59 +00:00
'#title' => $text,
);
return drupal_render($image);
2009-07-31 19:35:57 +00:00
}
2009-08-12 11:32:07 +00:00
2013-11-23 00:23:37 +00:00
/**
* Overrides theme_menu_local_action().
*/
function seven_menu_local_action($variables) {
$link = $variables['element']['#link'];
$link += array(
'href' => '',
'localized_options' => array(),
'route_parameters' => array(),
);
$link['localized_options']['attributes']['class'][] = 'button';
$link['localized_options']['attributes']['class'][] = 'button--primary';
$link['localized_options']['attributes']['class'][] = 'button--small';
// @todo Replace with a generalized solution for icons.
// See http://drupal.org/node/1849712
$link['localized_options']['attributes']['class'][] = 'button-action';
// We require Modernizr's touch test for button styling.
$libraries = array(
'#attached' => array(
'library' => array(
array('system', 'modernizr'),
),
),
);
drupal_render($libraries);
$output = '<li>';
// @todo Remove this check and the call to l() when all pages are converted to
// routes.
// @todo Figure out how to support local actions without a href properly.
if ($link['href'] === '' && !empty($link['route_name'])) {
$output .= Drupal::l($link['title'], $link['route_name'], $link['route_parameters'], $link['localized_options']);
}
else {
$output .= l($link['title'], $link['href'], $link['localized_options']);
}
$output .= "</li>";
return $output;
}
/**
* Implements hook_element_info_alter().
*/
function seven_element_info_alter(&$type) {
// We require Modernizr for button styling.
if (isset($type['button'])) {
$type['button']['#attached']['library'][] = array('system', 'modernizr');
}
}
2012-12-29 08:52:15 +00:00
/**
* Implements hook_preprocess_install_page().
*/
function seven_preprocess_install_page(&$variables) {
2013-07-14 20:17:23 +00:00
$variables['styles'] = new RenderWrapper('drupal_get_css');
$variables['scripts'] = new RenderWrapper('drupal_get_js');
2013-08-30 15:22:28 +00:00
// 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(
array('seven', 'install-page'),
),
),
);
drupal_render($libraries);
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.
*/
function seven_form_node_form_alter(&$form, &$form_state) {
2014-02-03 16:02:31 +00:00
/** @var \Drupal\node\NodeInterface $node */
2013-04-29 23:46:14 +00:00
$node = $form_state['controller']->getEntity();
2013-02-09 00:13:30 +00:00
2013-02-16 18:33:45 +00:00
$form['#theme'] = array('node_edit_form');
$form['#attached'] = array(
2013-06-07 10:48:55 +00:00
'css' => array(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';
$form['meta'] = array (
'#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')),
'#title' => t('Last saved'),
2013-08-16 17:13:11 +00:00
'#markup' => !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet'),
2013-02-09 00:13:30 +00:00
),
'author' => array(
'#type' => 'item',
'#wrapper_attributes' => array('class' => array('author', 'container-inline')),
'#title' => t('Author'),
2014-02-03 16:02:31 +00:00
'#markup' => $node->getOwner()->getUsername(),
2013-02-09 00:13:30 +00:00
),
);
$form['revision_information']['#type'] = 'container';
$form['revision_information']['#group'] = 'meta';
}