function revisioning_form_alter in Revisioning 7
Same name and namespace in other branches
- 8 revisioning.pages.inc \revisioning_form_alter()
- 6.4 revisioning.pages.inc \revisioning_form_alter()
- 6 revisioning.module \revisioning_form_alter()
- 6.3 revisioning.pages.inc \revisioning_form_alter()
Implements hook_form_alter().
Note: for cases where the FORM_ID is known a priori we use revisioning_form_FORMID_form_alter().
File
- ./
revisioning.pages.inc, line 14 - Rendering and altering of pages and forms used by Revisioning.
Code
function revisioning_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['#node_edit_form'])) {
$node =& $form['#node'];
$is_moderated_content = isset($node->revision_moderation) ? $node->revision_moderation : revisioning_content_is_moderated($form['type']['#value'], $node);
// Alter the Create/Edit content form, if subject to moderation.
if ($is_moderated_content) {
// "Create new revision" must be set when the node is to be moderated.
$node->revision = TRUE;
// Next line is not essential, just ensures form options are
// consistent with the edited content being subject to moderation.
$form['revision_information']['revision']['#default_value'] = TRUE;
// For moderated content "Published" box will be treated as unticked,
// See revisioning_node_presave().
}
// Only add this radio selector if user has the appropriate permissions.
// 'administer nodes' is required by default, but if configured
// appropriately, then any user premitted to publish this node will get the
// shortcut controls.
$add_radio_selector = variable_get('revisioning_publication_shortcuts', FALSE) ? revisioning_user_node_access('publish revisions', $node) : user_access('administer nodes');
if ($add_radio_selector) {
// Expand and move this vertical tab to top, so that it's in user's face.
if (isset($form['menu'])) {
$form['menu']['#collapsed'] = TRUE;
}
$form['revision_information']['#collapsed'] = FALSE;
$form['revision_information']['#weight'] = -3;
$options = array();
if (isset($node->nid)) {
$options[REVISIONING_NO_REVISION] = t('Modify current revision, no moderation');
}
$options[REVISIONING_NEW_REVISION_NO_MODERATION] = t('Create new revision, no moderation');
$options[REVISIONING_NEW_REVISION_WITH_MODERATION] = t('Create new revision and moderate');
// This radio selection will appear in hook_node_presave as
// $node->revision_operation
$form['revision_information']['revision_operation'] = array(
'#title' => t('Revision creation and moderation options'),
'#description' => t('Moderation means that the new revision is not publicly visible until approved by someone with the appropriate permissions.'),
'#type' => 'radios',
'#options' => $options,
'#default_value' => isset($node->nid) ? (int) $node->revision + (int) $is_moderated_content : ($is_moderated_content ? REVISIONING_NEW_REVISION_WITH_MODERATION : REVISIONING_NEW_REVISION_NO_MODERATION),
);
unset($form['revision_information']['revision']);
// Add javascript to show/hide the "Published" checkbox if the user
// presses one of the first two radio buttons. Also updates summary tabs.
$js_file = drupal_get_path('module', 'revisioning') . '/js/revisioning-radios.js';
// After node.js.
drupal_add_js($js_file, array(
'weight' => 1,
));
if (variable_get('revisioning_no_moderation_by_default', FALSE)) {
$form['revision_information']['revision_operation']['#default_value'] = REVISIONING_NEW_REVISION_NO_MODERATION;
}
}
else {
// For non-admin don't show radios, just set default, hidden on form.
// Note that $form['revision_information']['revision'] is already set.
$form['revision_moderation'] = array(
'#type' => 'value',
'#value' => $is_moderated_content,
);
}
// In addition to node_form_submit() append our own handler to the list, so
// that we can redirect to the pending, as opposed to current, revision.
$form['actions']['submit']['#submit'][] = '_revisioning_form_submit';
if (isset($form['actions']['delete']) && isset($form['actions']['delete']['#type'])) {
$nid = $form['#node']->nid;
if (revisioning_get_number_of_revisions($nid) > 1) {
// Special treatment for Delete button when there are >= 2 revisions.
if ($form['#node']->vid == revisioning_get_current_node_revision_id($nid)) {
// Make it obvious to user that a 'Delete' is in fact 'Delete all'.
$form['actions']['delete']['#value'] = t('Delete (all revisions)');
}
elseif (user_access('delete revisions')) {
// Change the meaning of the 'Delete' button when editing a revision
// to be the deletion of the viewed revision, rather than the node
// node.
$form['actions']['delete']['#value'] = t('Delete this revision');
$form['actions']['delete']['#submit'][] = '_revisioning_delete_submit';
}
}
}
}
}