Commit 19613d9b authored by alexpott's avatar alexpott

Issue #1843740 by webthingee, joelpittet, Hydra, thund3rbox, shrop: Convert...

Issue #1843740 by webthingee, joelpittet, Hydra, thund3rbox, shrop: Convert views/templates/views-exposed-form.tpl.php to twig.
parent a312df8c
{#
/**
* @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, if available.
* - 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.
* - form: A render element representing the form.
* - 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.
*
* @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 %}
<div class="views-exposed-form">
<div class="views-exposed-widgets clearfix">
{% for index, widget in widgets %}
<div id="{{ widget.id }}-wrapper" class="views-exposed-widget views-widget-{{ index }}">
{% if widget.label %}
<label for="{{ widget.id }}">
{{ widget.label }}
</label>
{% endif %}
{% if widget.operator %}
<div class="views-operator">
{{ widget.operator }}
</div>
{% endif %}
<div class="views-widget">
{{ widget.widget }}
</div>
{% if widget.description %}
<div class="description">
{{ widget.description }}
</div>
{% endif %}
</div>
{% endfor %}
{% if form.sort_by %}
<div class="views-exposed-widget views-widget-sort-by">
{{ form.sort_by }}
</div>
<div class="views-exposed-widget views-widget-sort-order">
{{ form.sort_order }}
</div>
{% endif %}
{% if form.items_per_page %}
<div class="views-exposed-widget views-widget-per-page">
{{ form.items_per_page }}
</div>
{% endif %}
{% if form.offset %}
<div class="views-exposed-widget views-widget-offset">
{{ form.offset }}
</div>
{% endif %}
<div class="views-exposed-widget views-submit-button">
{{ form }}
</div>
{% if form.reset_button %}
<div class="views-exposed-widget views-reset-button">
{{ form.reset_button }}
</div>
{% endif %}
</div>
</div>
<?php
/**
* @file
* This template handles the layout of the views exposed filter form.
*
* Variables available:
* - $widgets: An array of exposed form widgets. Each widget contains:
* - $widget->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
*/
?>
<?php if (!empty($q)): ?>
<?php
// This ensures that, if clean URLs are off, the 'q' is added first so that
// it shows up first in the URL.
print $q;
?>
<?php endif; ?>
<div class="views-exposed-form">
<div class="views-exposed-widgets clearfix">
<?php foreach ($widgets as $id => $widget): ?>
<div id="<?php print $widget->id; ?>-wrapper" class="views-exposed-widget views-widget-<?php print $id; ?>">
<?php if (!empty($widget->label)): ?>
<label for="<?php print $widget->id; ?>">
<?php print $widget->label; ?>
</label>
<?php endif; ?>
<?php if (!empty($widget->operator)): ?>
<div class="views-operator">
<?php print $widget->operator; ?>
</div>
<?php endif; ?>
<div class="views-widget">
<?php print $widget->widget; ?>
</div>
<?php if (!empty($widget->description)): ?>
<div class="description">
<?php print $widget->description; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php if (!empty($sort_by)): ?>
<div class="views-exposed-widget views-widget-sort-by">
<?php print $sort_by; ?>
</div>
<div class="views-exposed-widget views-widget-sort-order">
<?php print $sort_order; ?>
</div>
<?php endif; ?>
<?php if (!empty($items_per_page)): ?>
<div class="views-exposed-widget views-widget-per-page">
<?php print $items_per_page; ?>
</div>
<?php endif; ?>
<?php if (!empty($offset)): ?>
<div class="views-exposed-widget views-widget-offset">
<?php print $offset; ?>
</div>
<?php endif; ?>
<div class="views-exposed-widget views-submit-button">
<?php print $button; ?>
</div>
<?php if (!empty($reset_button)): ?>
<div class="views-exposed-widget views-reset-button">
<?php print $reset_button; ?>
</div>
<?php endif; ?>
</div>
</div>
......@@ -935,49 +935,57 @@ 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']);
}
$vars['widgets'][$id] = $widget;
// Unset the widget, so that it doesn't get rendered twice.
unset($form[$info['value']]);
}
// 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;
......@@ -985,22 +993,6 @@ function template_preprocess_views_exposed_form(&$vars) {
$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']);
}
if (isset($form['items_per_page'])) {
$vars['items_per_page'] = drupal_render($form['items_per_page']);
}
if (isset($form['offset'])) {
$vars['offset'] = drupal_render($form['offset']);
}
if (isset($form['reset'])) {
$vars['reset_button'] = drupal_render($form['reset']);
}
// This includes the submit button.
$vars['button'] = drupal_render_children($form);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment