function FilterPluginBase::showBuildGroupButton

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::showBuildGroupButton()
  2. 8.9.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::showBuildGroupButton()
  3. 10 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::showBuildGroupButton()

Shortcut to display the build_group/hide button.

1 call to FilterPluginBase::showBuildGroupButton()
FilterPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Provide the basic form which calls through to subforms.

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 429

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function showBuildGroupButton(&$form, FormStateInterface $form_state) {
    $form['group_button'] = [
        '#prefix' => '<div class="views-grouped clearfix">',
        '#suffix' => '</div>',
        // Should always come after the description and the relationship.
'#weight' => -190,
    ];
    $grouped_description = $this->t('Grouped filters allow a choice between predefined operator|value pairs.');
    $form['group_button']['radios'] = [
        '#theme_wrappers' => [
            'container',
        ],
        '#attributes' => [
            'class' => [
                'js-only',
            ],
        ],
    ];
    $form['group_button']['radios']['radios'] = [
        '#title' => $this->t('Filter type to expose'),
        '#description' => $grouped_description,
        '#type' => 'radios',
        '#options' => [
            $this->t('Single filter'),
            $this->t('Grouped filters'),
        ],
    ];
    if (empty($this->options['is_grouped'])) {
        $form['group_button']['markup'] = [
            '#markup' => '<div class="description grouped-description">' . $grouped_description . '</div>',
        ];
        $form['group_button']['button'] = [
            '#limit_validation_errors' => [],
            '#type' => 'submit',
            '#value' => $this->t('Grouped filters'),
            '#submit' => [
                [
                    $this,
                    'buildGroupForm',
                ],
            ],
        ];
        $form['group_button']['radios']['radios']['#default_value'] = 0;
    }
    else {
        $form['group_button']['button'] = [
            '#limit_validation_errors' => [],
            '#type' => 'submit',
            '#value' => $this->t('Single filter'),
            '#submit' => [
                [
                    $this,
                    'buildGroupForm',
                ],
            ],
        ];
        $form['group_button']['radios']['radios']['#default_value'] = 1;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.