function diff_form_alter in Diff 5
Same name and namespace in other branches
- 5.2 diff.module \diff_form_alter()
- 6.2 diff.module \diff_form_alter()
- 6 diff.module \diff_form_alter()
- 7.2 diff.module \diff_form_alter()
Implementation of hook_form_alter(). Used to add a 'Preview changes' button on the node edit form.
File
- ./
diff.module, line 442
Code
function diff_form_alter($form_id, &$form) {
if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
// Node editing form.
// Add a 'Preview changes' button.
if (variable_get('show_preview_changes_' . $form['type']['#value'], TRUE) && $form['nid']['#value'] > 0) {
$form['preview_changes'] = array(
'#type' => 'button',
'#value' => t('Preview changes'),
'#weight' => 41,
);
// Change the form render callback to display the new button
$form['#theme'] = 'diff_node_form';
// Add a callback to handle showing the diff if requested.
if (isset($form['#after_build']) && is_array($form['#after_build'])) {
$form['#after_build'][] = 'diff_node_form_add_changes';
}
else {
$form['#after_build'] = array(
'diff_node_form_add_changes',
);
}
}
}
elseif ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
// Node type edit form.
// Add checkbox to activate 'Preview changes' button per node type.
$form['workflow']['show_preview_changes'] = array(
'#type' => 'checkbox',
'#title' => t('Show %preview_changes button on node edit form', array(
'%preview_changes' => t('Preview changes'),
)),
'#prefix' => '<strong>' . t('Preview changes') . '</strong>',
'#weight' => 10,
'#default_value' => variable_get('show_preview_changes_' . $form['#node_type']->type, TRUE),
);
}
}