function block_inject_edit_form in Block Inject 7
Callback form to edit a region.
Parameters
int $id: Id of the region to be edited.
1 string reference to 'block_inject_edit_form'
- block_inject_menu in ./
block_inject.module - Implements hook_menu().
File
- ./
block_inject.admin.inc, line 285 - The admin functions for the module.
Code
function block_inject_edit_form($form, &$form_state, $id) {
// Get the region by the ID that came through the the URL.
$region = block_inject_get_region_by_id($id);
// Pass the region id through the form_state for the submit function.
$form_state['block_inject_region_id'] = $id;
$form['block_inject_region_name'] = array(
'#type' => 'textfield',
'#title' => t('Region name'),
'#description' => t('What is the name of the region you would like to inject?'),
'#required' => TRUE,
'#default_value' => check_plain($region->region),
);
// Get the available node types to be selected.
$available_node_types = block_inject_get_node_types();
// Get the node types selected by this region.
$sel_node_type_machine_array = explode(', ', $region->node_type);
$sel_node_type_name_array = explode(', ', $region->node_name);
$selected_node_types = array_combine($sel_node_type_machine_array, $sel_node_type_name_array);
// Add to the available node types the ones selected by this region.
$node_types_options = array_merge($available_node_types, $selected_node_types);
$form['block_inject_content_type'] = array(
'#type' => 'select',
'#title' => t('Available Content Type(s)'),
'#description' => t('Which content type would you like this region to be injected in the middle of?'),
'#options' => $node_types_options,
'#multiple' => TRUE,
'#default_value' => array_flip($selected_node_types),
);
$form['block_inject_conditionals_toggle'] = array(
'#title' => t('Would you like to condition the placement of the region injection?'),
'#type' => 'checkbox',
'#default_value' => $region->bi_condition ? 1 : 0,
);
// Unserialize condition.
if ($region->bi_condition) {
$condition = unserialize($region->bi_condition);
}
$form['block_inject_conditionals'] = array(
'#title' => t('The condition'),
'#type' => 'fieldset',
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
// Show only if conditional checkbox is selected.
'#states' => array(
'visible' => array(
'input[name="block_inject_conditionals_toggle"]' => array(
'checked' => TRUE,
),
),
),
);
$form['block_inject_conditionals']['block_inject_explanation_1'] = array(
'#type' => 'markup',
'#markup' => t('The destination needs to have '),
);
$form['block_inject_conditionals']['block_inject_paragraph_operator'] = array(
'#type' => 'select',
'#options' => array(
'<' => 'less than',
'=' => 'exactly',
'>' => 'more than',
),
'#multiple' => FALSE,
'#default_value' => isset($condition) ? $condition['condition']['operator'] : '<',
);
$form['block_inject_conditionals']['block_inject_paragraph_number'] = array(
'#type' => 'textfield',
'#maxlength' => 3,
'#size' => 4,
'#default_value' => isset($condition) ? $condition['condition']['paragraph_no'] : '',
);
$form['block_inject_conditionals']['block_inject_explanation_2'] = array(
'#type' => 'markup',
'#markup' => t(' paragraphs in order to fire the offset action below.'),
);
$form['block_inject_action'] = array(
'#title' => t('The action'),
'#type' => 'fieldset',
'#description' => t('The action to take if the condition above is met.'),
// Show only if conditional checkbox is selected.
'#states' => array(
'visible' => array(
'input[name="block_inject_conditionals_toggle"]' => array(
'checked' => TRUE,
),
),
),
);
$form['block_inject_action']['block_inject_paragraph_offset'] = array(
'#title' => t('Paragraph offset'),
'#type' => 'textfield',
'#description' => t('Please specify a positive or negative number to
offset the injection (e.g. 1 to move down by one paragraph /
-1 to move up by one paragraph).'),
'#default_value' => isset($condition) ? $condition['action']['offset'] : '',
);
$form['block_inject_region_submit'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
'#validate' => array(
'block_inject_add_inject_form_validate',
),
);
return $form;
}