function contextual_range_filter_config_form_submit in Views Contextual Range Filter 7
Execute contextual_range_filter_config_form.
1 string reference to 'contextual_range_filter_config_form_submit'
- contextual_range_filter_config_form in ./
contextual_range_filter.admin.inc - Menu callback for selecting which filters should become range filters.
File
Code
function contextual_range_filter_config_form_submit($form, &$form_state) {
// Clear out stuff we're not interested with.
form_state_values_clean($form_state);
foreach ($form_state['values'] as $type => $filters) {
// Clear out the unticked boxes.
$filters = array_filter($form_state['values'][$type]);
$prev_filters = variable_get($type, array());
$added_filters = array_diff($filters, $prev_filters);
$removed_filters = array_diff($prev_filters, $filters);
$changed_filters = array_merge($added_filters, $removed_filters);
if (empty($changed_filters)) {
continue;
}
variable_set($type, $filters);
// Find corresponding Views and save them.
$changed_view_names = array();
foreach ($changed_filters as $filter_name) {
if (isset($form['#view_names'][$filter_name])) {
$changed_view_names = array_merge($changed_view_names, $form['#view_names'][$filter_name]);
}
}
foreach (views_get_all_views() as $view) {
$view_name = empty($view->human_name) ? $view->name : $view->human_name;
if (in_array($view_name, $changed_view_names)) {
drupal_set_message(t('Saving view %view_name.', array(
'%view_name' => $view_name,
)));
// At this point contextual_range_filter_views_data_alter() has already
// been called and the new contextual filter handler set.
$view
->save();
}
}
}
drupal_set_message(t('The contextual range filters have been saved and their corresponding views updated where necessary.'));
}