diff -u b/autosave.api.php b/autosave.api.php --- b/autosave.api.php +++ b/autosave.api.php @@ -5,16 +5,16 @@ */ /** - * Implements hook_autosave_prevent(). + * Implements hook_autosave_prevent_alter(). * * @param $prevent_autosave * Set this to TRUE to prevent autosaving. * * More useful parameters are in $_POST. */ -function hook_autosave_prevent(&$prevent_autosave) { - $path = $_POST['autosave_form_path']; - $path_args = explode("/", $path); +function hook_autosave_prevent_alter(&$prevent_autosave) { + $path = $_POST['autosave_form_path']; + $path_args = explode("/", $path); // check if node has just been saved - if it has then it's because AS ajax fired off as user was submitting // if it had just been submitted - no need to AS now // - easy to figure out if we are submitting an edit to existing node @@ -31,5 +31,5 @@ ':type' => str_replace("-", "_", $path_args[2])))->fetchObject(); } - $prevent_autosave = $submitted ? TRUE : $prevent_autosave; + $prevent_autosave = ($submitted && (REQUEST_TIME - $submitted->changed < variable_get('autosave_period', 10))) ? TRUE : $prevent_autosave; } } diff -u b/autosave.module b/autosave.module --- b/autosave.module +++ b/autosave.module @@ -347,7 +347,6 @@ */ function autosave_save() { global $user; - // Possibility to prevent autosaving. $prevent_autosave = FALSE; drupal_alter('autosave_prevent', $prevent_autosave); @@ -355,7 +354,6 @@ $path = $_POST['autosave_form_path']; $form_id = $_POST['form_id']; // Not all variables need to be serialized. - // - for Drupal 6 version need to remove op and form_build_id unset($_POST['autosave_form_path'], $_POST['op'], $_POST['form_build_id']); $serialized = serialize($_POST); @@ -377,27 +375,28 @@ } /** - * Implements hook_autosave_prevent(). + * Implements hook_autosave_prevent_alter(). */ -function autosave_autosave_prevent(&$prevent_autosave) { - $path = $_POST['autosave_form_path']; - $path_args = explode("/", $path); +function autosave_autosave_prevent_alter(&$prevent_autosave) { + // TODO: Do something clever for not just node forms. + $path = $_POST['autosave_form_path']; + $path_args = explode("/", $path); // check if node has just been saved - if it has then it's because AS ajax fired off as user was submitting // if it had just been submitted - no need to AS now // - easy to figure out if we are submitting an edit to existing node // - little harder if we have just added a node if ($path_args[0] == 'node') { // update case - if (is_numeric($path_args[1])) { + if (($path_args[2] == 'edit') && is_numeric($path_args[1])) { $submitted = node_load($path_args[1]); } - else { + elseif ($path_args[1] == 'add') { // add case $submitted = db_query_range("SELECT created AS changed FROM {node} WHERE uid = :uid and type = :type ORDER BY created DESC", 0, 1, array( ':uid' => $user->uid, ':type' => str_replace("-", "_", $path_args[2])))->fetchObject(); } - $prevent_autosave = $submitted ? TRUE : $prevent_autosave; + $prevent_autosave = ($submitted && (REQUEST_TIME - $submitted->changed < variable_get('autosave_period', 10))) ? TRUE : $prevent_autosave; } }