function ddblock_select_nodes_js in Dynamic display block 7
Same name and namespace in other branches
- 6 ddblock.module \ddblock_select_nodes_js()
AHAH callback to replace node select options.
This function is called when the content type is changed. It updates the cached form (configure form) and returns rendered output to be used to replace the select containing the possible nodes in the newly selected content-type.
Parameters
$build_id: The form's build_id.
$ctid: A content type id from among those in the form's content type select.
Return value
Prints the replacement HTML in JSON format.
1 string reference to 'ddblock_select_nodes_js'
- ddblock_menu in ./
ddblock.module - Implements hook_menu().
File
- ./
ddblock.module, line 2491 - Enables your site to display dynamic content in a block.
Code
function ddblock_select_nodes_js() {
// get the form_id to rebuild the form later.
$form_id = $_POST['form_id'];
// get field settings from the form.
$content_type = $_POST['content_type'];
$nodes = $_POST['content_nodes'];
// get the form_build_id of the form to fetch the form from the cache_form table.
$form_build_id = $_POST['form_build_id'];
$form_state = array(
'submitted' => FALSE,
);
// Fetch the form from cache.
$form = form_get_cache($form_build_id, $form_state);
// Get the new fields.
ddblock_select_nodes_form($form, $content_type, $nodes);
// Store the form back in the cache.
form_set_cache($form_build_id, $form, $form_state);
// Build and render the new select element, then return it in JSON format.
$form_state = array();
$form['#post'] = array();
$form = form_builder($form_id, $form, $form_state);
$output = drupal_render($form['content']['content_types']['content_type']);
$output .= drupal_render($form['content']['content_types']['nodes']);
$output .= drupal_render($form['content']['content_types']['select_nodes']);
// Don't call drupal_json(). ahah.js uses an iframe and
// the header output by drupal_json() causes problems in some browsers.
print drupal_json_encode(array(
'status' => TRUE,
'data' => $output,
));
exit;
}