function FilterPluginBase::buildGroupSubmit

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

Save new group items, re-enumerates and remove groups marked to delete.

1 call to FilterPluginBase::buildGroupSubmit()
FilterPluginBase::submitOptionsForm in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Simple submit handler.

File

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

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function buildGroupSubmit($form, FormStateInterface $form_state) {
    $groups = [];
    $group_items = $form_state->getValue([
        'options',
        'group_info',
        'group_items',
    ]);
    uasort($group_items, [
        'Drupal\\Component\\Utility\\SortArray',
        'sortByWeightElement',
    ]);
    // Filter out removed items.
    // Start from 1 to avoid problems with #default_value in the widget.
    $new_id = 1;
    $new_default = 'All';
    foreach ($group_items as $id => $group) {
        if (empty($group['remove'])) {
            // Don't store this.
            unset($group['remove']);
            unset($group['weight']);
            $groups[$new_id] = $group;
            if ($form_state->getValue([
                'options',
                'group_info',
                'default_group',
            ]) == $id) {
                $new_default = $new_id;
            }
        }
        $new_id++;
    }
    if ($new_default != 'All') {
        $form_state->setValue([
            'options',
            'group_info',
            'default_group',
        ], $new_default);
    }
    $filter_default_multiple = $form_state->getValue([
        'options',
        'group_info',
        'default_group_multiple',
    ]);
    $form_state->setValue([
        'options',
        'group_info',
        'default_group_multiple',
    ], array_filter($filter_default_multiple));
    $form_state->setValue([
        'options',
        'group_info',
        'group_items',
    ], $groups);
}

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