function webformblock_form_alter in Webform Block 6.3
Same name and namespace in other branches
- 6 webformblock.module \webformblock_form_alter()
Add a checkbox on webform node editing page under 'advanced'. Allows the activating of a corresponding block
File
- ./
webformblock.module, line 13 - Expose webform nodes as Drupal blocks.
Code
function webformblock_form_alter(&$form, $form_state, $form_id) {
$node = $form['#parameters'][2];
// Webform 2
if ($form_id == 'webform_node_form') {
$form['webform']['advanced']['addblock'] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => webformblock_exists($node->nid),
'#title' => t('Generate a block'),
'#description' => t('Allow this form to appear in its own block which can be positioned in any block region.'),
'#weight' => -20,
);
}
elseif ($form_id == 'webform_configure_form') {
$form['advanced']['addblock'] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => webformblock_exists($node->nid),
'#title' => t('Generate a block'),
'#description' => t('Allow this form to appear in its own block which can be positioned in any block region.'),
'#weight' => -20,
);
$form['advanced']['use_teaser'] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => variable_get('webformblock_use_teaser_' . $node->nid, FALSE),
'#title' => t('Display the node teaser in the generated block'),
'#weight' => -19,
);
$form['#submit'][] = 'webformblock_config_form_submit';
}
if (strpos($form_id, 'webform_client_form_') === 0) {
if (webformblock_exists($node->nid)) {
// @todo: using an anchor only makes sense if errors are displayed close
// to the form.
//$anchor = str_replace(array('/', '_'), '', strtolower(drupal_get_path_alias('node/' . $node->nid)));
//$form['#action'] = url(drupal_get_path_alias($_GET['q']), array('fragment' => $anchor));
$current_url = url(drupal_get_path_alias($_GET['q']));
$form['#action'] = $current_url;
}
}
}