summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-25 05:13:58 (GMT)
committerAlex Pott2013-05-25 05:13:58 (GMT)
commit3cdae0550c8307294fd06ff4c102ee9831a428a4 (patch)
treeeccd42126cc3a4767aab91ee9cae4465ae9fa6c3
parentc9ff2332f9eda724af8d02fd0543d731caadd7d5 (diff)
Issue #1843744 by joelpittet, kgoel, Hydra, tsi, chrisjlee, shanethehat, jenlampton, mr.baileys, Cottser, socketwench: Convert views/templates/views-view.tpl.php to twig .
-rw-r--r--core/modules/views/templates/views-view.html.twig94
-rw-r--r--core/modules/views/templates/views-view.tpl.php90
-rw-r--r--core/modules/views/tests/views_test_data/templates/views-view--frontpage.html.twig89
-rw-r--r--core/modules/views/tests/views_test_data/templates/views-view--frontpage.tpl.php85
-rw-r--r--core/modules/views/views.theme.inc36
-rw-r--r--core/modules/views_ui/views_ui.module6
6 files changed, 207 insertions, 193 deletions
diff --git a/core/modules/views/templates/views-view.html.twig b/core/modules/views/templates/views-view.html.twig
new file mode 100644
index 0000000..7bc73b5
--- /dev/null
+++ b/core/modules/views/templates/views-view.html.twig
@@ -0,0 +1,94 @@
+{#
+/**
+ * @file
+ * Default theme implementation for main view template.
+ *
+ * Available variables:
+ * - attributes: Remaining HTML attributes for the element including:
+ * - class: HTML classes that can be used to style contextually
+ * through CSS, including:
+ * - view
+ * - view-[css_name]
+ * - view-id-[view_name]
+ * - view-display-id-[display_name]
+ * - view-dom-id-[dom_id]
+ * - css_name: A css-safe version of the view name.
+ * - css_class: The user-specified classes names, if any.
+ * - header: The optional header.
+ * - footer: The optional footer.
+ * - rows: The results of the view query, if any.
+ * - empty: The content to display if there are no rows.
+ * - pager: The optional pager next/prev links to display.
+ * - exposed: Exposed widget form/info to display.
+ * - feed_icon: An optional feed icon to display.
+ * - more: An optional link to the next page of results.
+ * - title: Title of the view, only used when displaying in the admin preview.
+ * - title_prefix: Additional output populated by modules, intended to be
+ * displayed in front of the view title.
+ * - title_suffix: Additional output populated by modules, intended to be
+ * displayed after the view title.
+ * - attachment_before: An optional attachment view to be displayed before the
+ * view content.
+ * - attachment_after: An optional attachment view to be displayed after the
+ * view content.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_views_view()
+ *
+ * @ingroup themeable
+ */
+#}
+<div{{ attributes }}>
+ {{ title_prefix }}
+ {% if title %}
+ {{ title }}
+ {% endif %}
+ {{ title_suffix }}
+ {% if header %}
+ <div class="view-header">
+ {{ header }}
+ </div>
+ {% endif %}
+ {% if exposed %}
+ <div class="view-filters">
+ {{ exposed }}
+ </div>
+ {% endif %}
+ {% if attachment_before %}
+ <div class="attachment attachment-before">
+ {{ attachment_before }}
+ </div>
+ {% endif %}
+
+ {% if rows %}
+ <div class="view-content">
+ {{ rows }}
+ </div>
+ {% elseif empty %}
+ <div class="view-empty">
+ {{ empty }}
+ </div>
+ {% endif %}
+
+ {% if pager %}
+ {{ pager }}
+ {% endif %}
+ {% if attachment_after %}
+ <div class="attachment attachment-after">
+ {{ attachment_after }}
+ </div>
+ {% endif %}
+ {% if more %}
+ {{ more }}
+ {% endif %}
+ {% if footer %}
+ <div class="view-footer">
+ {{ footer }}
+ </div>
+ {% endif %}
+ {% if feed_icon %}
+ <div class="feed-icon">
+ {{ feed_icon }}
+ </div>
+ {% endif %}
+</div>
diff --git a/core/modules/views/templates/views-view.tpl.php b/core/modules/views/templates/views-view.tpl.php
deleted file mode 100644
index ca8faef..0000000
--- a/core/modules/views/templates/views-view.tpl.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-
-/**
- * @file
- * Main view template.
- *
- * Variables available:
- * - $attributes: An instance of Attributes class that can be manipulated as an
- * array and printed as a string.
- * It includes the 'class' information, which includes:
- * .view
- * .view-[css_name]
- * .view-id-[view_name]
- * .view-display-id-[display_name]
- * .view-dom-id-[dom_id]
- * - $css_name: A css-safe version of the view name.
- * - $css_class: The user-specified classes names, if any
- * - $header: The view header
- * - $footer: The view footer
- * - $rows: The results of the view query, if any
- * - $empty: The empty text to display if the view is empty
- * - $pager: The pager next/prev links to display, if any
- * - $exposed: Exposed widget form/info to display
- * - $feed_icon: Feed icon to display, if any
- * - $more: A link to view more, if any
- *
- * @ingroup views_templates
- */
-?>
-<div <?php print $attributes; ?>>
- <?php print render($title_prefix); ?>
- <?php if ($title): ?>
- <?php print $title; ?>
- <?php endif; ?>
- <?php print render($title_suffix); ?>
- <?php if ($header): ?>
- <div class="view-header">
- <?php print render($header); ?>
- </div>
- <?php endif; ?>
-
- <?php if ($exposed): ?>
- <div class="view-filters">
- <?php print $exposed; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($attachment_before): ?>
- <div class="attachment attachment-before">
- <?php print render($attachment_before); ?>
- </div>
- <?php endif; ?>
-
- <?php if ($rows = render($rows)): ?>
- <div class="view-content">
- <?php print $rows; ?>
- </div>
- <?php elseif ($empty): ?>
- <div class="view-empty">
- <?php print render($empty); ?>
- </div>
- <?php endif; ?>
-
- <?php if ($pager): ?>
- <?php print $pager; ?>
- <?php endif; ?>
-
- <?php if ($attachment_after): ?>
- <div class="attachment attachment-after">
- <?php print render($attachment_after); ?>
- </div>
- <?php endif; ?>
-
- <?php if ($more): ?>
- <?php print $more; ?>
- <?php endif; ?>
-
- <?php if ($footer): ?>
- <div class="view-footer">
- <?php print render($footer); ?>
- </div>
- <?php endif; ?>
-
- <?php if ($feed_icon): ?>
- <div class="feed-icon">
- <?php print $feed_icon; ?>
- </div>
- <?php endif; ?>
-
-</div><?php /* class view */ ?>
diff --git a/core/modules/views/tests/views_test_data/templates/views-view--frontpage.html.twig b/core/modules/views/tests/views_test_data/templates/views-view--frontpage.html.twig
new file mode 100644
index 0000000..79a0e65
--- /dev/null
+++ b/core/modules/views/tests/views_test_data/templates/views-view--frontpage.html.twig
@@ -0,0 +1,89 @@
+{#
+/**
+ * @file
+ * Default theme implementation for the frontpage view template.
+ *
+ * Available variables:
+ * - attributes: Remaining HTML attributes for the element including:
+ * - class: HTML classes that can be used to style contextually
+ * through CSS, including:
+ * - view
+ * - view-[css_name]
+ * - view-id-[view_name]
+ * - view-display-id-[display_name]
+ * - view-dom-id-[dom_id]
+ * - css_name: A css-safe version of the view name.
+ * - css_class: The user-specified classes names, if any.
+ * - header: The optional header.
+ * - footer: The optional footer.
+ * - rows: The results of the view query, if any.
+ * - empty: The content to display if there are no rows.
+ * - pager: The optional pager next/prev links to display.
+ * - exposed: Exposed widget form/info to display.
+ * - feed_icon: An optional feed icon to display.
+ * - more: An optional link to the next page of results.
+ * - title: Title of the view, only used when displaying in the admin preview.
+ * - title_prefix: Additional output populated by modules, intended to be
+ * displayed in front of the view title.
+ * - title_suffix: Additional output populated by modules, intended to be
+ * displayed after the view title.
+ * - attachment_before: An optional attachment view to be displayed before the
+ * view content.
+ * - attachment_after: An optional attachment view to be displayed after the
+ * view content.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_views_view()
+ *
+ * @ingroup themeable
+ */
+#}
+<div{{ attributes }}>
+ {% if header %}
+ <div class="view-header">
+ {{ header }}
+ </div>
+ {% endif %}
+ {% if exposed %}
+ <div class="view-filters">
+ {{ exposed }}
+ </div>
+ {% endif %}
+ {% if attachment_before %}
+ <div class="attachment attachment-before">
+ {{ attachment_before }}
+ </div>
+ {% endif %}
+
+ {% if rows %}
+ <div class="view-content">
+ {{ rows }}
+ </div>
+ {% elseif empty %}
+ <div class="view-empty">
+ {{ empty }}
+ </div>
+ {% endif %}
+
+ {% if pager %}
+ {{ pager }}
+ {% endif %}
+ {% if attachment_after %}
+ <div class="attachment attachment-after">
+ {{ attachment_after }}
+ </div>
+ {% endif %}
+ {% if more %}
+ {{ more }}
+ {% endif %}
+ {% if footer %}
+ <div class="view-footer">
+ {{ footer }}
+ </div>
+ {% endif %}
+ {% if feed_icon %}
+ <div class="feed-icon">
+ {{ feed_icon }}
+ </div>
+ {% endif %}
+</div>
diff --git a/core/modules/views/tests/views_test_data/templates/views-view--frontpage.tpl.php b/core/modules/views/tests/views_test_data/templates/views-view--frontpage.tpl.php
deleted file mode 100644
index 5e6c8fa..0000000
--- a/core/modules/views/tests/views_test_data/templates/views-view--frontpage.tpl.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-
-/**
- * @file
- * Main view template.
- *
- * Variables available:
- * - $attributes: An instance of Attributes class that can be manipulated as an
- * array and printed as a string.
- * It includes the 'class' information, which includes:
- * .view
- * .view-[css_name]
- * .view-id-[view_name]
- * .view-display-id-[display_name]
- * .view-dom-id-[dom_id]
- * - $css_name: A css-safe version of the view name.
- * - $css_class: The user-specified classes names, if any
- * - $header: The view header
- * - $footer: The view footer
- * - $rows: The results of the view query, if any
- * - $empty: The empty text to display if the view is empty
- * - $pager: The pager next/prev links to display, if any
- * - $exposed: Exposed widget form/info to display
- * - $feed_icon: Feed icon to display, if any
- * - $more: A link to view more, if any
- *
- * @ingroup views_templates
- */
-?>
-<div <?php print $attributes; ?>>
- <?php if ($header): ?>
- <div class="view-header">
- <?php print $header; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($exposed): ?>
- <div class="view-filters">
- <?php print $exposed; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($attachment_before): ?>
- <div class="attachment attachment-before">
- <?php print $attachment_before; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($rows): ?>
- <div class="view-content">
- <?php print $rows; ?>
- </div>
- <?php elseif ($empty): ?>
- <div class="view-empty">
- <?php print $empty; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($pager): ?>
- <?php print $pager; ?>
- <?php endif; ?>
-
- <?php if ($attachment_after): ?>
- <div class="attachment attachment-after">
- <?php print $attachment_after; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($more): ?>
- <?php print $more; ?>
- <?php endif; ?>
-
- <?php if ($footer): ?>
- <div class="view-footer">
- <?php print $footer; ?>
- </div>
- <?php endif; ?>
-
- <?php if ($feed_icon): ?>
- <div class="feed-icon">
- <?php print $feed_icon; ?>
- </div>
- <?php endif; ?>
-
-</div> <?php /* class view */ ?>
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 82a4a1f..bd9500d 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -11,11 +11,11 @@ use Drupal\views\ViewExecutable;
/**
* Provide a full array of possible themes to try for a given hook.
*
- * @param $hook
+ * @param string $hook
* The hook to use. This is the base theme/template name.
- * @param $view
+ * @param \Drupal\views\ViewExecutable $view
* The view being rendered.
- * @param $display
+ * @param string|null $display
* The display being rendered, if applicable.
*/
function _views_theme_functions($hook, ViewExecutable $view, $display = NULL) {
@@ -40,14 +40,20 @@ function _views_theme_functions($hook, ViewExecutable $view, $display = NULL) {
}
/**
- * Preprocess the primary theme implementation for a view.
+ * Prepares variables for view templates.
+ *
+ * Default template: views-view.html.twig.
+ *
+ * @param array $vars
+ * An associative array containing:
+ * - view: The ViewExecutable object.
*/
function template_preprocess_views_view(&$vars) {
global $base_path;
$view = $vars['view'];
- $vars['rows'] = (!empty($view->result) || $view->style_plugin->even_empty()) ? $view->style_plugin->render($view->result) : '';
+ $vars['rows'] = (!empty($view->result) || $view->style_plugin->even_empty()) ? $view->style_plugin->render($view->result) : array();
// Force a render array so CSS/JS can be added.
if (!is_array($vars['rows'])) {
$vars['rows'] = array('#markup' => $vars['rows']);
@@ -57,7 +63,7 @@ function template_preprocess_views_view(&$vars) {
$vars['id'] = $view->storage->id();
$vars['display_id'] = $view->current_display;
- // Basic classes
+ // Basic classes.
$vars['css_class'] = '';
$vars['attributes']['class'] = array();
@@ -110,21 +116,21 @@ function template_preprocess_views_view(&$vars) {
// attached to an array (not an object) in order to process them. For our
// purposes, it doesn't matter what we attach them to, since once they are
// processed by contextual_preprocess() they will appear in the $title_suffix
- // variable (which we will then render in views-view.tpl.php).
+ // variable (which we will then render in views-view.html.twig).
views_add_contextual_links($vars['view_array'], 'view', $view, $view->current_display);
// Attachments are always updated with the outer view, never by themselves,
// so they do not have dom ids.
if (empty($view->is_attachment)) {
- // Our JavaScript needs to have some means to find the HTML belonging to this
- // view.
+ // Our JavaScript needs to have some means to find the HTML belonging to
+ // this view.
//
// It is true that the DIV wrapper has classes denoting the name of the view
// and its display ID, but this is not enough to unequivocally match a view
// with its HTML, because one view may appear several times on the page. So
- // we set up a hash with the current time, $dom_id, to issue a "unique" identifier for
- // each view. This identifier is written to both Drupal.settings and the DIV
- // wrapper.
+ // we set up a hash with the current time, $dom_id, to issue a "unique"
+ // identifier for each view. This identifier is written to both
+ // Drupal.settings and the DIV wrapper.
$vars['dom_id'] = $view->dom_id;
$vars['attributes']['class'][] = 'view-dom-id-' . $vars['dom_id'];
}
@@ -153,7 +159,7 @@ function template_preprocess_views_view(&$vars) {
$view->element['#attached']['library'][] = array('views', 'views.ajax');
}
- // If form fields were found in the View, reformat the View output as a form.
+ // If form fields were found in the view, reformat the view output as a form.
if (views_view_has_form_elements($view)) {
// Copy the rows so as not to modify them by reference when rendering.
$rows = $vars['rows'];
@@ -1192,7 +1198,7 @@ function theme_views_mini_pager($vars) {
* or some combination thereof.
*
* For each view, there will be a minimum of two templates used. The first
- * is used for all views: views-view.tpl.php.
+ * is used for all views: views-view.html.twig.
*
* The second template is determined by the style selected for the view. Note
* that certain aspects of the view can also change which style is used; for
@@ -1212,7 +1218,7 @@ function theme_views_mini_pager($vars) {
* - views-view--foobar--page.tpl.php
* - views-view--page.tpl.php
* - views-view--foobar.tpl.php
- * - views-view.tpl.php
+ * - views-view.html.twig
*
* - views-view-unformatted--foobar--page.html.twig
* - views-view-unformatted--page.html.twig
diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module
index 0d461be..0c8bbf4 100644
--- a/core/modules/views_ui/views_ui.module
+++ b/core/modules/views_ui/views_ui.module
@@ -220,7 +220,7 @@ function views_ui_library_info() {
}
/**
- * Theme preprocess for views-view.tpl.php.
+ * Implements hook_preprocess_HOOK() for views-view.html.twig.
*/
function views_ui_preprocess_views_view(&$vars) {
$view = $vars['view'];
@@ -232,11 +232,11 @@ function views_ui_preprocess_views_view(&$vars) {
'#theme' => 'views_ui_view_preview_section',
'#view' => $view,
'#section' => $section,
- '#content' => is_array($vars[$section]) ? drupal_render($vars[$section]) : $vars[$section],
+ '#content' => $vars[$section],
'#theme_wrappers' => array('views_ui_container'),
'#attributes' => array('class' => 'contextual-region'),
);
- $vars[$section] = drupal_render($vars[$section]);
+ $vars[$section] = $vars[$section];
}
}
}