function contextual_view_modes_settings_submit in Contextual View Modes 7
[contextual_view_modes_settings_submit description]
Parameters
[type] $form [description]:
[type] $form_state [description]:
Return value
[type] [description]
2 string references to 'contextual_view_modes_settings_submit'
- contextual_view_modes_settings in ./
contextual_view_modes.admin.inc - [contextual_view_modes_settings description]
- contextual_view_modes_settings_validate in ./
contextual_view_modes.admin.inc - [contextual_view_modes_settings_validate description]
File
- ./
contextual_view_modes.admin.inc, line 141 - Contextual View Modes Administrative Screens
Code
function contextual_view_modes_settings_submit($form, &$form_state) {
$values = array_merge($form_state['values'], $form_state['storage']);
$disabled_types = array_filter($values['cvm_enabled_content_types'], '_give_zero_values');
// LOOP THROUGH DISABLED TYPES AND REMOVE FIELD INSTANCES.
foreach ($disabled_types as $type => $nothing) {
$cvm_instance = field_read_instance('node', CVM_FIELD_NAME, $type);
if ($cvm_instance) {
$instance = _get_cvm_field_instance($type);
field_delete_instance($instance, FALSE);
}
}
// Remove content types from the list that arent enabled and then
// store the values of the form.
$filtered = array_filter($values['cvm_enabled_content_types'], '_remove_zero_values');
$keys = array_keys($filtered);
variable_set('cvm_enabled_content_types', $keys);
// Attach CVM field instances to the enabled content types
// We now have a list of content types (bundles) that we need to attach an
// instance of the fields to. Loop through them and attach them.
$cvm_field = field_info_field(CVM_FIELD_NAME);
foreach ($keys as $k => $v) {
$cvm_instance = field_read_instance('node', CVM_FIELD_NAME, $v);
if (!$cvm_instance) {
// Create it.
$instance = _get_cvm_field_instance($v);
field_create_instance($instance);
}
}
// HANDLE THE DEFAULT VIEW MODE SETTINGS.
// We want to store these in a nice big arrary instead of individual variables
// in the systems form. Lets make sure we parse them and unset them form the
// form state.
$global_cvm = array();
foreach ($values as $field_name => $value) {
if (substr($field_name, 0, 12) == "cvmglobal___") {
// Remove from form_state.
unset($form_state['values'][$field_name]);
// We dont care about no values...
if ($value == "none") {
continue;
}
$xp = explode("___", $field_name);
unset($xp[0]);
// Dont need this.
$content_type = $xp[1];
unset($xp[1]);
$context_name = implode("___", $xp);
// If field was disabled we need to not store it.
if (array_key_exists($content_type, $disabled_types)) {
continue;
}
$global_cvm[$content_type][$context_name] = $value;
}
}
variable_set('cvm_global_content_type_modes', $global_cvm);
drupal_set_message('Configuration Settings Saved');
// Clear all the caches.
drupal_flush_all_caches();
}