function template_preprocess_views_ui_build_group_filter_form
Same name in other branches
- 8.9.x core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_build_group_filter_form()
- 10 core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_build_group_filter_form()
- 11.x core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_build_group_filter_form()
Prepares variables for Views UI build group filter form templates.
Default template: views-ui-build-group-filter-form.html.twig.
Parameters
array $variables: An associative array containing:
- form: A render element representing the form.
File
-
core/
modules/ views_ui/ views_ui.theme.inc, line 104
Code
function template_preprocess_views_ui_build_group_filter_form(&$variables) {
$form = $variables['form'];
// Prepare table of options.
$header = [
t('Default'),
t('Weight'),
t('Label'),
t('Operator'),
t('Value'),
t('Operations'),
];
// Prepare default selectors.
$form_state = new FormState();
$form['default_group'] = Radios::processRadios($form['default_group'], $form_state, $form);
$form['default_group_multiple'] = Checkboxes::processCheckboxes($form['default_group_multiple'], $form_state, $form);
$form['default_group']['All']['#title'] = '';
$rows[] = [
[
'data' => $form['default_group']['All'],
],
'',
[
'data' => \Drupal::config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('<Any>') : t('- Any -'),
'colspan' => 4,
'class' => [
'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'] = '';
$default = [
$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>', [], [
'attributes' => [
'id' => 'views-remove-link-' . $group_id,
'class' => [
'views-hidden',
'views-button-remove',
'views-groups-remove-link',
'views-remove-link',
],
'alt' => t('Remove this item'),
'title' => t('Remove this item'),
],
]),
'#title' => new FormattableMarkup('<span>@text</span>', [
'@text' => t('Remove'),
]),
];
$remove = [
$form['group_items'][$group_id]['remove'],
$link,
];
$data = [
'default' => [
'data' => $default,
],
'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[] = [
'data' => $data,
'id' => 'views-row-' . $group_id,
'class' => [
'draggable',
],
];
}
$variables['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => [
'class' => [
'views-filter-groups',
],
'id' => 'views-filter-groups',
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'weight',
],
],
];
// Hide fields used in table.
unset($variables['form']['group_items']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.