Submit handler for form buttons that do not complete a form workflow.
The Edit View form is a multistep form workflow, but with state managed by the TempStore rather than $form_state['rebuild']. Without this submit handler, buttons that add or remove displays would redirect to the destination parameter (e.g., when the Edit View form is linked to from a contextual link). This handler can be added to buttons whose form submission should not yet redirect to the destination.
public function submitDelayDestination($form, &$form_state) {
$query = drupal_container()
->get('request')->query;
// @todo: Revisit this when http://drupal.org/node/1668866 is in.
$destination = $query
->get('destination');
if (isset($destination) && $form_state['redirect'] !== FALSE) {
if (!isset($form_state['redirect'])) {
$form_state['redirect'] = current_path();
}
if (is_string($form_state['redirect'])) {
$form_state['redirect'] = array(
$form_state['redirect'],
);
}
$options = isset($form_state['redirect'][1]) ? $form_state['redirect'][1] : array();
if (!isset($options['query']['destination'])) {
$options['query']['destination'] = $destination;
}
$form_state['redirect'][1] = $options;
$query
->remove('destination');
}
}