function block_inject_edit_form_submit in Block Inject 7
Submit form to edit a region.
File
- ./
block_inject.admin.inc, line 385 - The admin functions for the module.
Code
function block_inject_edit_form_submit($form, &$form_state) {
// Get region
$region = $form_state['values']['block_inject_region_name'];
// Run the name through the function to check if it is already in use.
$name_test = block_inject_check_region_name($region);
if ($name_test == TRUE || $region == $form['block_inject_region_name']['#default_value']) {
if (isset($form_state['input']['block_inject_content_type'])) {
// If set, retrieve the machine name of the selected node typs.
$node_type_array = $form_state['input']['block_inject_content_type'];
// Retrieve the names of the selected node types.
$node_type_name_array = array_flip(array_intersect(array_flip($form_state['complete form']['block_inject_content_type']['#options']), $node_type_array));
// Implode the node type arrays.
$node_type_name = check_plain(implode(', ', $node_type_name_array));
$node_type = check_plain(implode(', ', $node_type_array));
}
else {
$node_type = '';
$node_type_name = '';
}
// Check if region name was provided and add to database.
if ($region) {
$id = $form_state['block_inject_region_id'];
// Process conditions for the inject if there are any
if ($form_state['values']['block_inject_conditionals_toggle'] == 1) {
if (is_numeric($form_state['values']['block_inject_paragraph_number']) && is_numeric($form_state['values']['block_inject_paragraph_offset'])) {
$condition = array(
'condition' => array(
'operator' => $form_state['values']['block_inject_paragraph_operator'],
'paragraph_no' => $form_state['values']['block_inject_paragraph_number'],
),
'action' => array(
'offset' => $form_state['values']['block_inject_paragraph_offset'],
),
);
}
$serialized = serialize($condition);
block_inject_update_region($id, $region, $node_type, $node_type_name, $serialized);
}
else {
block_inject_update_region($id, $region, $node_type, $node_type_name);
}
// Redirect back to main Block Inject page.
$form_state['redirect'] = 'admin/structure/block-inject';
block_inject_rebuild_data();
drupal_set_message(t('Your region has been updated.'), 'status');
}
else {
drupal_set_message(t('There was an error'), 'error');
}
}
else {
drupal_set_message(t('Duplicate region name. Please choose another one!'), 'error');
}
}