function ViewsUiThemeHooks::preprocessBuildGroupFilterForm
Same name and namespace in other branches
- main core/modules/views_ui/src/Hook/ViewsUiThemeHooks.php \Drupal\views_ui\Hook\ViewsUiThemeHooks::preprocessBuildGroupFilterForm()
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/ src/ Hook/ ViewsUiThemeHooks.php, line 202
Class
- ViewsUiThemeHooks
- Hook implementations for views_ui.
Namespace
Drupal\views_ui\HookCode
public function preprocessBuildGroupFilterForm(array &$variables) : void {
$form = $variables['form'];
// Prepare table of options.
$header = [
$this->t('Default'),
$this->t('Weight'),
$this->t('Label'),
$this->t('Operator'),
$this->t('Value'),
$this->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' => $this->configFactory
->get('views.settings')
->get('ui.exposed_filter_any_label') == 'old_any' ? $this->t('<Any>') : $this->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' => $this->t('Remove this item'),
'title' => $this->t('Remove this item'),
],
]),
'#title' => new FormattableMarkup('<span>@text</span>', [
'@text' => $this->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.