Commit 08baa72a authored by alexpott's avatar alexpott

Issue #1963978 by joelpittet, NickWilde, jmolivas, dimaro, lauriii, Manuel...

Issue #1963978 by joelpittet, NickWilde, jmolivas, dimaro, lauriii, Manuel Garcia, 2ndmile, Cottser, tim.plunkett: Convert theme_views_ui_build_group_filter_form() to Twig
parent 94615a13
{#
/**
* @file
* Default theme implementation for Views UI build group filter form.
*
* Available variables:
* - form: A render element representing the form. Contains the following:
* - form_description: The exposed filter's description.
* - expose_button: The button to toggle the expose filter form.
* - group_button: Toggle options between single and grouped filters.
* - label: A filter label input field.
* - description: A filter description field.
* - value: The filters available values.
* - optional: A checkbox to require this filter or not.
* - remember: A checkbox to remember selected filter value(s) (per user).
* - widget: Radio Buttons to select the filter widget.
* - add_group: A button to add another row to the table.
* - more: A details element for additional field exposed filter fields.
* - table: A rendered table element of the group filter form.
*
* @see template_preprocess_views_ui_build_group_filter_form()
*
* @ingroup themeable
*/
#}
{{ form.form_description }}
{{ form.expose_button }}
{{ form.group_button }}
<div class="views-left-40">
{{ form.optional }}
{{ form.remember }}
</div>
<div class="views-right-60">
{{ form.widget }}
{{ form.label }}
{{ form.description }}
</div>
{#
Render the rest of the form elements excluding elements that are rendered
elsewhere.
#}
{{ form|without(
'form_description',
'expose_button',
'group_button',
'optional',
'remember',
'widget',
'label',
'description',
'add_group',
'more'
)
}}
{{ table }}
{{ form.add_group }}
{{ form.more }}
......@@ -8,12 +8,8 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
use Drupal\views_ui\ViewUI;
use Drupal\views\Analyzer;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Component\Utility\Xss;
/**
......@@ -97,7 +93,6 @@ function views_ui_theme() {
'views_ui_build_group_filter_form' => array(
'render element' => 'form',
'file' => 'views_ui.theme.inc',
'function' => 'theme_views_ui_build_group_filter_form',
),
// On behalf of a plugin
......
......@@ -65,35 +65,18 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) {
}
/**
* Theme the build group filter form.
* Prepares variables for Views UI build group filter form templates.
*
* @ingroup themeable
* Default template: views-ui-build-group-filter-form.html.twig.
*
* @param array $variables
* An associative array containing:
* - form: A render element representing the form.
*/
function theme_views_ui_build_group_filter_form($variables) {
function template_preprocess_views_ui_build_group_filter_form(&$variables) {
$form = $variables['form'];
$more = drupal_render($form['more']);
$output = drupal_render($form['form_description']);
$output .= drupal_render($form['expose_button']);
$output .= drupal_render($form['group_button']);
if (isset($form['required'])) {
$output .= drupal_render($form['required']);
}
$output .= drupal_render($form['operator']);
$output .= drupal_render($form['value']);
$output .= '<div class="views-left-40">';
$output .= drupal_render($form['optional']);
$output .= drupal_render($form['remember']);
$output .= '</div>';
$output .= '<div class="views-right-60">';
$output .= drupal_render($form['widget']);
$output .= drupal_render($form['label']);
$output .= drupal_render($form['description']);
$output .= '</div>';
// Prepare table of options.
$header = array(
t('Default'),
t('Weight'),
......@@ -103,14 +86,14 @@ function theme_views_ui_build_group_filter_form($variables) {
t('Operations'),
);
// Prepare default selectors.
$form_state = new FormState();
$form['default_group'] = Element\Radios::processRadios($form['default_group'], $form_state, $form);
$form['default_group_multiple'] = Element\Checkboxes::processCheckboxes($form['default_group_multiple'], $form_state, $form);
$form['default_group']['All']['#title'] = '';
hide($form['default_group_multiple']['All']);
$rows[] = array(
drupal_render($form['default_group']['All']),
['data' => $form['default_group']['All']],
'',
array(
'data' => \Drupal::config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('&lt;Any&gt;') : t('- Any -'),
......@@ -118,6 +101,9 @@ function theme_views_ui_build_group_filter_form($variables) {
'class' => array('class' => 'any-default-radios-row'),
),
);
// Remove the 'All' default_group form element because it's added to the
// table row.
unset($variables['form']['default_group']['All']);
foreach (Element::children($form['group_items']) as $group_id) {
$form['group_items'][$group_id]['value']['#title'] = '';
......@@ -125,6 +111,10 @@ function theme_views_ui_build_group_filter_form($variables) {
$form['default_group'][$group_id],
$form['default_group_multiple'][$group_id],
];
// Remove these fields from the form since they are moved into the table.
unset($variables['form']['default_group'][$group_id]);
unset($variables['form']['default_group_multiple'][$group_id]);
$link = [
'#type' => 'link',
'#url' => Url::fromRoute('<none>', [], [
......@@ -145,15 +135,15 @@ function theme_views_ui_build_group_filter_form($variables) {
$remove = [$form['group_items'][$group_id]['remove'], $link];
$data = array(
'default' => ['data' => $default],
'weight' => drupal_render($form['group_items'][$group_id]['weight']),
'title' => drupal_render($form['group_items'][$group_id]['title']),
'operator' => drupal_render($form['group_items'][$group_id]['operator']),
'value' => drupal_render($form['group_items'][$group_id]['value']),
'weight' => ['data' => $form['group_items'][$group_id]['weight']],
'title' => ['data' => $form['group_items'][$group_id]['title']],
'operator' => ['data' => $form['group_items'][$group_id]['operator']],
'value' => ['data' => $form['group_items'][$group_id]['value']],
'remove' => ['data' => $remove],
);
$rows[] = array('data' => $data, 'id' => 'views-row-' . $group_id, 'class' => array('draggable'));
}
$table = array(
$variables['table'] = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
......@@ -170,11 +160,8 @@ function theme_views_ui_build_group_filter_form($variables) {
),
);
// Render the "Add another item" button below the table.
$add_another = drupal_render($form['add_group']);
$render_form = drupal_render_children($form);
return $output . $render_form . drupal_render($table) . $add_another . $more;
// Hide fields used in table.
unset($variables['form']['group_items']);
}
/**
......
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