Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By joel_guesclin on
I'm trying to upgrade the checkout module to 4.7 and everything going tickety-boo... I've pretty much got the stuff about hook_nodeapi and hoo_form_alter sorted... BUT!!!
In my hook_form_alter I call drupal_set_message to warn the user that his node has been checked out when he loads the form to edit the node. When I press on "Submit" the node is updated... and the message still gets displayed, just above the "page was updated" message. What is happening? Is hook_form_alter getting called twice? Has the message not been cleared, and if so how to clear it?
Here is the code:
function checkout_form_alter($form_id, &$form) {
global $user;
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
if (user_access('checkout documents')) {
$node = $form['#node'];
if ($node->nid) {
$data = checkout_checkout($node->nid);
if ($data->uid != $user->uid) {
checkout_message($data);
}
if (variable_get("checkout_long", 0 ) > 0) {
// _form_form code follows:
$form['checkout']['checkout'] = array(
'#type' => 'checkbox',
'#title' => t('Checkout this document on saving?'),
'#return_value' => 1,
'#weight' => -15,
'#default_value' => FALSE,
'#description' => t('If you want to check out this document and so prevent other users from modifying until you next edit it, then tick this box'),
);
// the final return is not needed because $form is a reference.
drupal_set_message(t('This document is now locked against simultaneous editing. It will unlock when you navigate elsewhere, unless you check the box to reserve the document in your name.'));
}
else {
drupal_set_message(t('This document is now locked against simultaneous editing. It will unlock when you navigate elsewhere.'));
}
}
}
}
}