commit e547699725e3706891796106ef7163c28db31ed5 Author: Patrick Goddard Date: Wed May 8 13:13:38 2013 -0700 Issue 1843740 by tostinni: Convert core PHPTemplate files and theme functions to Twig diff --git a/core/modules/views/templates/views-exposed-form.html.twig b/core/modules/views/templates/views-exposed-form.html.twig new file mode 100644 index 0000000..78b85ac --- /dev/null +++ b/core/modules/views/templates/views-exposed-form.html.twig @@ -0,0 +1,86 @@ +{# +/** + * @file + * Default theme implementation of a Views exposed form. + * + * Available variables: + * - widgets: A list of exposed form widgets. Each widget contains: + * - label: The sanitized label of the widget. + * - id: The id of the widget, or an empty string. + * - operator: The select element for the operator widget. + * - description: The sanitized description of the widget. + * - widget: The widget itself. + * - index: the widget's row index. + * - sort_by: An optional select element to sort the View by fields. + * - sort_order: An optional select element with ascending or + * descending order options. + * - items_per_page: An optional select element for the available items per page. + * - offset: An optional textfield to define the offset of the View. + * - reset_button: An optional button to reset the exposed filter applied. + * - button: The submit button for the form. + * + * @see template_preprocess() + * @see template_preprocess_views_exposed_form() + * + * @ingroup themeable + */ +#} +{% if q is not empty %} + {# + This ensures that, if clean URLs are off, the 'q' is added first, + as a hidden form element, so that it shows up first in the POST URL. + #} +{{ q }} +{% endif %} +
+
+ {% for index, widget in widgets %} +
+ {% if widget.label %} + + {% endif %} + {% if widget.operator %} +
+ {{ widget.operator }} +
+ {% endif %} +
+ {{ widget.widget }} +
+ {% if widget.description %} +
+ {{ widget.description }} +
+ {% endif %} +
+ {% endfor %} + {% if sort_by %} +
+ {{ sort_by }} +
+
+ {{ sort_order }} +
+ {% endif %} + {% if items_per_page %} +
+ {{ items_per_page }} +
+ {% endif %} + {% if offset %} +
+ {{ offset }} +
+ {% endif %} +
+ {{ button }} +
+ {% if reset_button %} +
+ {{ reset_button }} +
+ {% endif %} +
+
diff --git a/core/modules/views/templates/views-exposed-form.tpl.php b/core/modules/views/templates/views-exposed-form.tpl.php deleted file mode 100644 index bdd570c..0000000 --- a/core/modules/views/templates/views-exposed-form.tpl.php +++ /dev/null @@ -1,80 +0,0 @@ -label: The visible label to print. May be optional. - * - $widget->operator: The operator for the widget. May be optional. - * - $widget->widget: The widget itself. - * - $sort_by: The select box to sort the view using an exposed form. - * - $sort_order: The select box with the ASC, DESC options to define order. May be optional. - * - $items_per_page: The select box with the available items per page. May be optional. - * - $offset: A textfield to define the offset of the view. May be optional. - * - $reset_button: A button to reset the exposed filter applied. May be optional. - * - $button: The submit button for the form. - * - * @ingroup views_templates - */ -?> - - - -
-
- $widget): ?> -
- label)): ?> - - - operator)): ?> -
- operator; ?> -
- -
- widget; ?> -
- description)): ?> -
- description; ?> -
- -
- - -
- -
-
- -
- - -
- -
- - -
- -
- -
- -
- -
- -
- -
-
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc old mode 100644 new mode 100755 index 4178bac..ac6e9ac --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -939,39 +939,45 @@ function template_preprocess_views_view_row_rss(&$vars) { } /** - * Default theme function for all filter forms. + * Prepares variables for Views exposed form templates. + * + * Default template: views-exposed-form.html.twig. + * + * @param array $vars + * An associative array containing: + * - form: A render element representing the form. */ function template_preprocess_views_exposed_form(&$vars) { $form = &$vars['form']; // Put all single checkboxes together in the last spot. - $checkboxes = ''; + $checkboxes = array(); if (!empty($form['q'])) { - $vars['q'] = drupal_render($form['q']); + $vars['q'] = $form['q']; } $vars['widgets'] = array(); foreach ($form['#info'] as $id => $info) { // Set aside checkboxes. if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') { - $checkboxes .= drupal_render($form[$info['value']]); + $checkboxes[] = $form[$info['value']]; continue; } $widget = new stdClass(); // set up defaults so that there's always something there. - $widget->label = $widget->operator = $widget->widget = $widget->description = NULL; + $widget->label = $widget->operator = $widget->widget = $widget->description = ''; $widget->id = isset($form[$info['value']]['#id']) ? $form[$info['value']]['#id'] : ''; if (!empty($info['label'])) { $widget->label = check_plain($info['label']); } - if (!empty($info['operator'])) { - $widget->operator = drupal_render($form[$info['operator']]); + if (!empty($info['operator']) && isset($form[$info['operator']])) { + $widget->operator = $form[$info['operator']]; } - $widget->widget = drupal_render($form[$info['value']]); + $widget->widget = $form[$info['value']]; if (!empty($info['description'])) { $widget->description = check_plain($info['description']); @@ -981,37 +987,37 @@ function template_preprocess_views_exposed_form(&$vars) { } // Wrap up all the checkboxes we set aside into a widget. - if ($checkboxes) { + if (!empty($checkboxes)) { $widget = new stdClass(); // set up defaults so that there's always something there. - $widget->label = $widget->operator = $widget->widget = NULL; + $widget->label = $widget->operator = $widget->widget = ''; $widget->id = 'checkboxes'; $widget->widget = $checkboxes; $vars['widgets']['checkboxes'] = $widget; } if (isset($form['sort_by'])) { - $vars['sort_by'] = drupal_render($form['sort_by']); - $vars['sort_order'] = drupal_render($form['sort_order']); + $vars['sort_by'] = $form['sort_by']; + $vars['sort_order'] = $form['sort_order']; } if (isset($form['items_per_page'])) { - $vars['items_per_page'] = drupal_render($form['items_per_page']); + $vars['items_per_page'] = $form['items_per_page']; } if (isset($form['offset'])) { - $vars['offset'] = drupal_render($form['offset']); + $vars['offset'] = $form['offset']; } if (isset($form['reset'])) { - $vars['reset_button'] = drupal_render($form['reset']); + $vars['reset_button'] = $form['reset']; } // This includes the submit button. - $vars['button'] = drupal_render_children($form); + $vars['button'] = $form['submit']; } /** * Theme function for a View with form elements: replace the placeholders. */ -function theme_views_form_views_form($variables) { - $form = $variables['form']; +function theme_views_form_views_form($vars) { + $form = $vars['form']; // Placeholders and their substitutions (usually rendered form elements). $search = array();