summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-07-04 18:27:35 +0100
committerAlex Pott2014-07-04 18:27:35 +0100
commitbec1967bd9b81e391f31f668aa48b996ffb63621 (patch)
treee3d9a745a518f0c054de42f5608c207146dd8603
parent74e9426c035a8871125d29c700989bb6d50b4058 (diff)
Issue #1987424 by rteijeiro, oshelach, a-fro, JeroenT, joelpittet, Cottser, IshaDakota, InternetDevels, TommyK, Sutharsan, robmc, mark.labrecque, lokapujya, Gaelan, drupalninja99, Carolyn, jenlampton, longwave: Seven.theme - Convert theme_ functions to Twig.
-rw-r--r--core/themes/seven/seven.theme99
-rw-r--r--core/themes/seven/templates/admin-block-content.html.twig25
-rw-r--r--core/themes/seven/templates/block-content-add-list.html.twig26
-rw-r--r--core/themes/seven/templates/node-add-list.html.twig29
-rw-r--r--core/themes/seven/templates/tablesort-indicator.html.twig16
5 files changed, 123 insertions, 72 deletions
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme
index 74592cf..5585065 100644
--- a/core/themes/seven/seven.theme
+++ b/core/themes/seven/seven.theme
@@ -110,104 +110,59 @@ function seven_menu_local_task($variables) {
}
/**
- * Displays the list of available node types for node creation.
+ * Implements hook_preprocess_HOOK() for list of available node type templates.
*/
-function seven_node_add_list($variables) {
- $content = $variables['content'];
- if ($content) {
- $output = '<ul class="admin-list">';
- foreach ($content as $type) {
- $output .= '<li class="clearfix">';
- $content = '<span class="label">' . String::checkPlain($type->name) . '</span>';
- $content .= '<div class="description">' . Xss::filterAdmin($type->description) . '</div>';
- $options['html'] = TRUE;
- $output .= l($content, 'node/add/' . $type->type, $options);
- $output .= '</li>';
+function seven_preprocess_node_add_list(&$variables) {
+ if (!empty($variables['content'])) {
+ foreach ($variables['content'] as $type) {
+ $variables['types'][$type->type]['label'] = String::checkPlain($type->name);
+ $variables['types'][$type->type]['description'] = Xss::filterAdmin($type->description);
+ $variables['types'][$type->type]['url'] = \Drupal::url('node.add', array('node_type' => $type->type));
}
- $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>';
+ $variables['add_content_type_url'] = \Drupal::url('node.type_add');
}
- return $output;
}
/**
- * Overrides theme_block_content_add_list().
+ * Implements hook_preprocess_HOOK() for block content add list templates.
*
- * Displays the list of available custom block types for creation.
+ * Displays the list of available custom block types for creation, adding
+ * separate variables for the label, description, and url.
*/
-function seven_block_content_add_list($variables) {
- $output = '';
- if (!empty($variables['types'])) {
- $output = '<ul class="admin-list">';
- foreach ($variables['types'] as $id => $type) {
- $output .= '<li class="clearfix">';
- $content = '<span class="label">' . String::checkPlain($type['title']) . '</span>';
- $content .= '<div class="description">' . Xss::filterAdmin($type['description']) . '</div>';
- $options = $type['localized_options'];
- $options['html'] = TRUE;
- $output .= \Drupal::l($content, 'block_content.add_form', array('block_content_type' => $id), $options);
- $output .= '</li>';
+function seven_preprocess_block_content_add_list(&$variables) {
+ if (!empty($variables['content'])) {
+ foreach ($variables['content'] as $type) {
+ $variables['types'][$type->id()]['label'] = String::checkPlain($type->label());
+ $variables['types'][$type->id()]['description'] = Xss::filterAdmin($type->description);
+ $options = array('query' => \Drupal::request()->query->all());
+ $variables['types'][$type->id()]['url'] = \Drupal::url('block_content.add_form', array('block_content_type' => $type->id()), $options);
}
- $output .= '</ul>';
}
- return $output;
}
/**
- * Overrides theme_admin_block_content().
- *
- * Uses an unordered list markup in both compact and extended mode.
+ * Implements hook_preprocess_HOOK() for block admin page templates.
*/
-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">' . Xss::filterAdmin($item['title']) . '</span>';
- $options = $item['localized_options'];
- $options['html'] = TRUE;
- if (isset($item['description']) && !system_admin_compact_mode()) {
- $content .= '<div class="description">' . Xss::filterAdmin($item['description']) . '</div>';
- }
- $output .= l($content, $item['link_path'], $options);
- $output .= '</li>';
+function seven_preprocess_admin_block_content(&$variables) {
+ if (!empty($variables['content'])) {
+ foreach ($variables['content'] as $key => $item) {
+ $variables['content'][$key]['url'] = url($item['link_path']);
}
- $output .= '</ul>';
}
- return $output;
}
/**
- * Overrides theme_tablesort_indicator().
+ * Implements hook_preprocess_HOOK() for tablesort indicator templates.
*
* Uses Seven's image versions, so the arrows show up as black and not gray on
* gray.
*/
-function seven_tablesort_indicator($variables) {
+function seven_preprocess_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' => 9,
- '#height' => 5,
- '#title' => $text,
- );
- return drupal_render($image);
+ $variables['arrow_asc'] = file_create_url($theme_path . '/images/arrow-asc.png');
+ $variables['arrow_desc'] = file_create_url($theme_path . '/images/arrow-desc.png');
}
/**
diff --git a/core/themes/seven/templates/admin-block-content.html.twig b/core/themes/seven/templates/admin-block-content.html.twig
new file mode 100644
index 0000000..7dc0a92
--- /dev/null
+++ b/core/themes/seven/templates/admin-block-content.html.twig
@@ -0,0 +1,25 @@
+{#
+/**
+ * @file
+ * Seven's theme implementation for the content of an administrative block.
+ *
+ * Uses unordered list markup in both compact and extended modes.
+ *
+ * Available variables:
+ * - content: List of administrative menu items. Each menu item contains:
+ * - url: Path to the admin section.
+ * - title: Short name of the section.
+ * - description: Description of the administrative menu item.
+ * - attributes: HTML attributes to be added to the element.
+ *
+ * @see template_preprocess_admin_block_content()
+ * @see seven_preprocess_admin_block_content()
+ */
+#}
+{% if content %}
+ <ul{{ attributes }}>
+ {% for item in content %}
+ <li><a href="{{ item.url }}"><span class="label">{{ item.title }}</span><div class="description">{{ item.description }}</div></a></li>
+ {% endfor %}
+ </ul>
+{% endif %}
diff --git a/core/themes/seven/templates/block-content-add-list.html.twig b/core/themes/seven/templates/block-content-add-list.html.twig
new file mode 100644
index 0000000..0c0c496
--- /dev/null
+++ b/core/themes/seven/templates/block-content-add-list.html.twig
@@ -0,0 +1,26 @@
+{#
+/**
+ * @file
+ * Seven's theme implementation to display a list of custom block types.
+ *
+ * Displays the list of available custom block types for creation.
+ *
+ * Available variables:
+ * - types: A collection of all the available custom block types.
+ * Each type contains:
+ * - url: A link to add a block of this type.
+ * - description: A description of this custom block type.
+ * - label: The title of the custom block type.
+ * - path: A path for the link to add a block of this type.
+ *
+ * @see template_preprocess_block_content_add_list()
+ * @see seven_preprocess_block_content_add_list()
+ */
+ #}
+<ul class="admin-list">
+ {% for type in types %}
+ <li class="clearfix">
+ <a href="{{ type.url }}"><span class="label">{{ type.label }}</span><div class="description">{{ type.description }}</div></a>
+ </li>
+ {% endfor %}
+</ul>
diff --git a/core/themes/seven/templates/node-add-list.html.twig b/core/themes/seven/templates/node-add-list.html.twig
new file mode 100644
index 0000000..4d5e020
--- /dev/null
+++ b/core/themes/seven/templates/node-add-list.html.twig
@@ -0,0 +1,29 @@
+{#
+/**
+ * @file
+ * Seven's theme implementation to list node types available for adding content.
+ *
+ * Available variables:
+ * - types: List of content types. Each content type contains:
+ * - url: Path to the add content of this type page.
+ * - label: The title of this type of content.
+ * - description: Description of this type of content.
+ * - add_content_type_url: Path to the add content type page.
+ *
+ * @see template_preprocess_node_add_list()
+ * @see seven_preprocess_node_add_list()
+ */
+#}
+{% if content %}
+ <ul class="admin-list">
+ {% for type in types %}
+ <li class="clearfix"><a href="{{ type.url }}"><span class="label">{{ type.label }}</span><div class="description">{{ type.description }}</div></a></li>
+ {% endfor %}
+ </ul>
+{% else %}
+ <p>
+ {% trans %}
+ You have not created any content types yet. Go to the <a href="{{ add_content_type_url }}">content type creation page</a> to add a new content type.
+ {% endtrans %}
+ </p>
+{% endif %}
diff --git a/core/themes/seven/templates/tablesort-indicator.html.twig b/core/themes/seven/templates/tablesort-indicator.html.twig
new file mode 100644
index 0000000..b2eadaa
--- /dev/null
+++ b/core/themes/seven/templates/tablesort-indicator.html.twig
@@ -0,0 +1,16 @@
+{#
+/**
+ * @file
+ * Seven's theme implementation for displaying a tablesort indicator.
+ *
+ * Available variables:
+ * - style: Either 'asc' or 'desc', indicating the sorting direction.
+ * - arrow_asc: URL to the image for an ascending arrow.
+ * - arrow_desc: URL to the image for a descending arrow.
+ */
+#}
+{% if style == 'asc' -%}
+ <img src="{{ arrow_asc }}" width="9" height="5" alt="{{ 'Sort ascending'|t }}" title="{{ 'Sort ascending'|t }}" />
+{% else -%}
+ <img src="{{ arrow_desc }}" width="9" height="5" alt="{{ 'Sort descending'|t }}" title="{{ 'Sort descending'|t }}" />
+{% endif %}