} // Update our cache with values so that cancel still works the way
// people expect.
$view->form_cache =
[ 'key' => 'rearrange-filter',
'groups' =>
$groups,
'handlers' =>
$new_fields,
];
// Return to this form except on actual Update.
$view->
addFormToStack('rearrange-filter',
$form_state->
get('display_id'
), 'filter'
);
} else { // The actual update button was clicked. Remove the empty groups, and
// renumber them sequentially.
ksort($remember_groups);
$groups['groups'
] =
static::
arrayKeyPlus(array_values(array_intersect_key($groups['groups'
],
$remember_groups)));
// Change the 'group' key on each field to match. Here, $mapping is an
// array whose keys are the old group numbers and whose values are the new
// (sequentially numbered) ones.
$mapping =
array_flip(static::
arrayKeyPlus(array_keys($remember_groups)));
foreach ($new_fields as &
$new_field) {