public function views_ef_fieldset_display_extender_plugin::arrange_submit in Views Exposed Form Fieldset 7.2
Submit callback for the arrange form.
Persists form changes without actually submitting and saving the changes.
File
- views/
views_ef_fieldset_display_extender_plugin.inc, line 251 - Provides a display extender plugin for View 3.x.
Class
- views_ef_fieldset_display_extender_plugin
- @file Provides a display extender plugin for View 3.x.
Code
public function arrange_submit(&$form, &$form_state) {
$trigger = !empty($form_state['triggering_element']) ? $form_state['triggering_element'] : NULL;
// #action is a custom element key that makes it easier to identify the
// clicked button.
$action = isset($trigger['#action']) ? $trigger['#action'] : NULL;
$values = $form_state['values'] + array(
'items' => array(),
);
$items = $values['items'];
switch ($action) {
// Add a new item.
case 'item_add':
// Other submit callbacks may access this plugin using
// $form_state['view']->display_handler->extender['views_ef_fieldset'].
$manager = $this
->get_manager();
if ($item = $manager
->getItem($values['item_add'])) {
$items[$item['id']] = $item;
}
break;
// Remove a single item.
case 'item_remove':
list($id) = array_slice($trigger['#parents'], -2, 1) + array(
NULL,
);
if (isset($items[$id])) {
unset($items[$id]);
}
// @todo Reassign weights so that children of removed element are placed before next element.
break;
default:
}
// Remove form-specific extra values to avoid polluting the item
// definitions.
// @todo Consider using data objects instead of plain arrays.
$clean_keys = array_flip(array(
'id',
'pid',
'weight',
'options',
));
foreach ($items as $id => $item) {
$items[$id] = array_intersect_key($item, $clean_keys);
}
// form_cache allows us to persist option changes across multiple requests
// without having to set them directly in the view (which would make
// cancelling impossible. It will be cleared automatically if a form gets
// cancelled (see e.g. views_ui_standard_cancel()) or if form_cache['key']
// does not match the current form key (see views_ui_ajax_form()).
// Clearing the form cache will only take effect once another form is
// submitted (or cancelled) and the view gets cached again.
//
// Unfortunately almost all Views UI forms share the form key "display".
// It is therefore a good idea to use your own namespace in form_cache
// instead of relying on views_ui_ajax_form() to clear it for you.
// Also, due to a Views bug using the form cache can temporarily break the
// filter arrange form. See https://www.drupal.org/node/2716593.
$form_state['view']->form_cache = array(
'key' => $form_state['form_key'],
);
$this
->set_cached_option('items', $items);
// Add the current form identifier to the stack so that the form will be
// loaded again. In combination with the form_cache property this enables
// a behavior similar to standard forms with $form_state['cache'] = TRUE
// and $form_state['rebuild'] = TRUE.
views_ui_add_form_to_stack($form_state['form_key'], $form_state['view'], $form_state['display_id'], array(
$form_state['section'],
));
// Persist changes to the form cache.
views_ui_cache_set($form_state['view']);
}