seven.theme 6.78 KB
Newer Older
1 2
<?php

3
/**
4 5 6 7
 * @file
 * Functions to support theming in the Seven theme.
 */

8 9
use Drupal\Core\Template\RenderWrapper;

10 11 12 13 14 15 16
/**
 * Implements hook_library_info().
 */
function seven_library_info() {
  $path = drupal_get_path('theme', 'seven');

  $libraries['install-page'] = array(
17
    'version' => \Drupal::VERSION,
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    'js' => array(
      $path . '/js/mobile.install.js' => array(
        'group' => JS_THEME,
      ),
    ),
    'css' => array(
      $path . '/install-page.css' => array(
        'group' => CSS_AGGREGATE_THEME,
      ),
    ),
  );

  return $libraries;
}

33
/**
34
 * Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
35
 */
36
function seven_preprocess_maintenance_page(&$variables) {
37 38
  // 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
39
  // maintenance-page.html.twig template. So, to have what's done in
40 41
  // seven_preprocess_html() also happen on the maintenance page, it has to be
  // called here.
42
  seven_preprocess_html($variables);
43 44
}

45
/**
46
 * Implements hook_preprocess_HOOK() for html.tpl.php.
47
 */
48
function seven_preprocess_html(&$variables) {
49
  drupal_add_library('system', 'normalize');
50
}
51 52

/**
53
 * Implements hook_preprocess_HOOK() for page.tpl.php.
54
 */
55 56 57 58
function seven_preprocess_page(&$variables) {
  $variables['primary_local_tasks'] = $variables['tabs'];
  unset($variables['primary_local_tasks']['#secondary']);
  $variables['secondary_local_tasks'] = array(
59
    '#theme' => 'menu_local_tasks',
60
    '#secondary' => isset($variables['tabs']['#secondary']) ? $variables['tabs']['#secondary'] : '',
61
  );
62 63 64
}

/**
65
 * Displays the list of available node types for node creation.
66
 */
67 68
function seven_node_add_list($variables) {
  $content = $variables['content'];
69
  if ($content) {
70
    $output = '<ul class="admin-list">';
71
    foreach ($content as $type) {
72
      $output .= '<li class="clearfix">';
73 74 75 76
      $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);
77 78 79 80
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
81 82 83
  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>';
  }
84 85 86
  return $output;
}

87 88 89 90 91 92 93
/**
 * Overrides theme_custom_block_add_list().
 *
 * Displays the list of available custom block types for creation.
 */
function seven_custom_block_add_list($variables) {
  $output = '';
94
  if (!empty($variables['types'])) {
95
    $output = '<ul class="admin-list">';
96
    foreach ($variables['types'] as $id => $type) {
97
      $output .= '<li class="clearfix">';
98 99 100
      $content = '<span class="label">' . check_plain($type['title']) . '</span>';
      $content .= '<div class="description">' . filter_xss_admin($type['description']) . '</div>';
      $options = $type['localized_options'];
101
      $options['html'] = TRUE;
102
      $output .= \Drupal::l($content, 'custom_block.add_form', array('custom_block_type' => $id), $options);
103 104 105 106 107 108 109
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}

110
/**
111
 * Overrides theme_admin_block_content().
112
 *
113
 * Uses an unordered list markup in both compact and extended mode.
114
 */
115 116
function seven_admin_block_content($variables) {
  $content = $variables['content'];
117 118 119 120
  $output = '';
  if (!empty($content)) {
    $output = system_admin_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
    foreach ($content as $item) {
121 122 123 124
      $output .= '<li>';
      $content = '<span class="label">' . filter_xss_admin($item['title']) . '</span>';
      $options = $item['localized_options'];
      $options['html'] = TRUE;
125
      if (isset($item['description']) && !system_admin_compact_mode()) {
126
        $content .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
127
      }
128
      $output .= l($content, $item['href'], $options);
129 130 131 132 133 134 135 136
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}

/**
137
 * Overrides theme_tablesort_indicator().
138
 *
139 140
 * Uses Seven's image versions, so the arrows show up as black and not gray on
 * gray.
141
 */
142
function seven_tablesort_indicator($variables) {
143
  $theme_path = drupal_get_path('theme', 'seven');
144 145 146

  if($variables['style'] == 'asc') {
    $image_uri = $theme_path . '/images/arrow-asc.png';
147
    $text = t('Sort ascending');
148 149
  }
  else {
150
    $image_uri = $theme_path . '/images/arrow-desc.png';
151
    $text = t('Sort descending');
152
  }
153 154 155 156 157

  $image = array(
    '#theme' => 'image',
    '#uri' => $image_uri,
    '#alt' => $text,
158 159
    '#width' => 9,
    '#height' => 5,
160 161 162
    '#title' => $text,
  );
  return drupal_render($image);
163
}
164

165 166 167 168
/**
 * Implements hook_preprocess_install_page().
 */
function seven_preprocess_install_page(&$variables) {
169 170
  $variables['styles'] = new RenderWrapper('drupal_get_css');
  $variables['scripts'] = new RenderWrapper('drupal_get_js');
171 172 173 174 175 176 177 178 179 180 181

  // 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);
182
}
183 184 185 186 187 188 189

/**
 * 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) {
190
  $node = $form_state['controller']->getEntity();
191

192 193
  $form['#theme'] = array('node_edit_form');
  $form['#attached'] = array(
194
    'css' => array(drupal_get_path('module', 'node') . '/css/node.module.css'),
195 196
  );

197 198 199 200 201 202 203 204 205 206
  $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')),
207
      '#markup' => $node->isPublished() ? t('Published') : t('Not published'),
208
      '#access' => !$node->isNew(),
209 210 211 212 213
    ),
    'changed' => array(
      '#type' => 'item',
      '#wrapper_attributes' => array('class' => array('changed', 'container-inline')),
      '#title' => t('Last saved'),
214
      '#markup' => !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet'),
215 216 217 218 219
    ),
    'author' => array(
      '#type' => 'item',
      '#wrapper_attributes' => array('class' => array('author', 'container-inline')),
      '#title' => t('Author'),
220
      '#markup' => $node->getAuthor()->getUsername(),
221 222 223 224 225
    ),
  );
  $form['revision_information']['#type'] = 'container';
  $form['revision_information']['#group'] = 'meta';
}