function block_inject_add_inject_form_submit in Block Inject 7
Submit form that adds the new region to the database.
File
- ./
block_inject.admin.inc, line 225 - The admin functions for the module.
Code
function block_inject_add_inject_form_submit($form, &$form_state) {
$region = $form_state['values']['block_inject_region_name'];
if (isset($form_state['values']['block_inject_content_type'])) {
// If set, retrieve the machine name of the selected node typs.
$node_type_array = $form_state['values']['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, process condition and add to database.
if ($region) {
// 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'],
),
);
}
else {
// Need to do a better validation handling here with _validate.
return drupal_set_message(t('Please make sure the paragraph number is an
integer'), 'error');
}
$serialized = serialize($condition);
block_inject_add_region($region, $node_type, $node_type_name, $serialized);
}
else {
block_inject_add_region($region, $node_type, $node_type_name);
}
// Redirect back to main Block Inject page.
$form_state['redirect'] = 'admin/structure/block-inject';
// Rebuild data and clear cache.
block_inject_rebuild_data();
drupal_set_message(t('Your region has been added.'), 'status');
}
else {
drupal_set_message(t('There was an error'), 'error');
}
}