seven.theme

Functions to support theming in the Seven theme.

File

drupal/core/themes/seven/seven.theme
View source
<?php

/**
 * @file
 * Functions to support theming in the Seven theme.
 */

/**
 * Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
 */
function seven_preprocess_maintenance_page(&$vars) {

  // While markup for normal pages is split into page.tpl.php and html.tpl.php,
  // the markup for the maintenance page is all in the single
  // maintenance-page.html.twig template. So, to have what's done in
  // seven_preprocess_html() also happen on the maintenance page, it has to be
  // called here.
  seven_preprocess_html($vars);
}

/**
 * Implements hook_preprocess_HOOK() for html.tpl.php.
 */
function seven_preprocess_html(&$vars) {
  drupal_add_library('system', 'normalize');

  // Add conditional CSS for IE8 and below.
  drupal_add_css(path_to_theme() . '/ie.css', array(
    'group' => CSS_AGGREGATE_THEME,
    'browsers' => array(
      'IE' => 'lte IE 8',
      '!IE' => FALSE,
    ),
    'weight' => 999,
    'preprocess' => FALSE,
  ));
}

/**
 * Implements hook_preprocess_HOOK() for page.tpl.php.
 */
function seven_preprocess_page(&$vars) {
  $vars['primary_local_tasks'] = $vars['tabs'];
  unset($vars['primary_local_tasks']['#secondary']);
  $vars['secondary_local_tasks'] = array(
    '#theme' => 'menu_local_tasks',
    '#secondary' => isset($vars['tabs']['#secondary']) ? $vars['tabs']['#secondary'] : '',
  );
}

/**
 * Displays the list of available node types for node creation.
 */
function seven_node_add_list($variables) {
  $content = $variables['content'];
  $output = '';
  if ($content) {
    $output = '<ul class="admin-list">';
    foreach ($content as $type) {
      $output .= '<li class="clearfix">';
      $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);
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  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>';
  }
  return $output;
}

/**
 * Overrides theme_custom_block_add_list().
 *
 * Displays the list of available custom block types for creation.
 */
function seven_custom_block_add_list($variables) {
  $content = $variables['content'];
  $output = '';
  if ($content) {
    $output = '<ul class="admin-list">';
    foreach ($content as $type) {
      $output .= '<li class="clearfix">';
      $content = '<span class="label">' . check_plain($type
        ->label()) . '</span>';
      $content .= '<div class="description">' . filter_xss_admin($type->description) . '</div>';
      $options['html'] = TRUE;
      $output .= l($content, 'block/add/' . $type
        ->id(), $options);
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}

/**
 * Overrides theme_admin_block_content().
 *
 * Uses an unordered list markup in both compact and extended mode.
 */
function seven_admin_block_content($variables) {
  $content = $variables['content'];
  $output = '';
  if (!empty($content)) {
    $output = system_admin_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
    foreach ($content as $item) {
      $output .= '<li>';
      $content = '<span class="label">' . filter_xss_admin($item['title']) . '</span>';
      $options = $item['localized_options'];
      $options['html'] = TRUE;
      if (isset($item['description']) && !system_admin_compact_mode()) {
        $content .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
      }
      $output .= l($content, $item['href'], $options);
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}

/**
 * Overrides theme_tablesort_indicator().
 *
 * Uses Seven's image versions, so the arrows show up as black and not gray on
 * gray.
 */
function seven_tablesort_indicator($variables) {
  $theme_path = drupal_get_path('theme', 'seven');
  if ($variables['style'] == 'asc') {
    $image_uri = $theme_path . '/images/arrow-asc.png';
    $text = t('sort ascending');
  }
  else {
    $image_uri = $theme_path . '/images/arrow-desc.png';
    $text = t('sort descending');
  }
  $image = array(
    '#theme' => 'image',
    '#uri' => $image_uri,
    '#alt' => $text,
    '#width' => 13,
    '#height' => 13,
    '#title' => $text,
  );
  return drupal_render($image);
}

/**
 * Implements hook_preprocess_install_page().
 */
function seven_preprocess_install_page(&$variables) {
  drupal_add_js(drupal_get_path('theme', 'seven') . '/js/mobile.install.js');
}

/**
 * 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) {
  $node = $form_state['controller']
    ->getEntity();
  $form['#theme'] = array(
    'node_edit_form',
  );
  $form['#attached'] = array(
    'css' => array(
      drupal_get_path('module', 'node') . '/css/node.module.css',
    ),
  );
  $form['advanced']['#type'] = 'container';
  $form['meta'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'entity-meta-header',
      ),
    ),
    '#type' => 'container',
    '#group' => 'advanced',
    '#weight' => -100,
    'published' => array(
      '#type' => 'item',
      '#wrapper_attributes' => array(
        'class' => array(
          'published',
        ),
      ),
      '#markup' => !empty($node->status) ? t('Published') : t('Not published'),
      '#access' => !empty($node->nid),
    ),
    'changed' => array(
      '#type' => 'item',
      '#wrapper_attributes' => array(
        'class' => array(
          'changed',
          'container-inline',
        ),
      ),
      '#title' => t('Last saved'),
      '#markup' => !$node
        ->isNew() ? format_date($node->changed, 'short') : t('Not saved yet'),
    ),
    'author' => array(
      '#type' => 'item',
      '#wrapper_attributes' => array(
        'class' => array(
          'author',
          'container-inline',
        ),
      ),
      '#title' => t('Author'),
      '#markup' => user_format_name(user_load($node->uid)),
    ),
  );
  $form['revision_information']['#type'] = 'container';
  $form['revision_information']['#group'] = 'meta';
}

Functions

Namesort descending Description
seven_admin_block_content Overrides theme_admin_block_content().
seven_custom_block_add_list Overrides theme_custom_block_add_list().
seven_form_node_form_alter Implements hook_form_BASE_FORM_ID_alter().
seven_node_add_list Displays the list of available node types for node creation.
seven_preprocess_html Implements hook_preprocess_HOOK() for html.tpl.php.
seven_preprocess_install_page Implements hook_preprocess_install_page().
seven_preprocess_maintenance_page Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
seven_preprocess_page Implements hook_preprocess_HOOK() for page.tpl.php.
seven_tablesort_indicator Overrides theme_tablesort_indicator().