The "Save and continue" button is there to allow you to keep editing the node instead of redirecting to the node view page.

This works except when the URL parameter destination is set. In that case, it always redirects to the destination because of how drupal_goto() and Form API redirection works.

Proposed solution #16 is to clear the destination and redirect to the node edit page with the destination set again, so that the destination is not lost.

Comments

tr’s picture

If you're talking about the save and continue button on the node edit form node/%/edit, that is controlled by Drupal. Ubercart has nothing to do with this. If you're not talking about that button, well maybe you could spare a few more keystrokes to fully describe your request.

longwave’s picture

"Save and continue" is actually added by uc_product_form_alter() to product node forms.

shp’s picture

Yes, I mean the button on the node edit form.

that is controlled by Drupal. Ubercart has nothing to do with this

I've made some analysis :) See the drupal_goto() source code. When there are $_REQUEST['destination'] or $_REQUEST['edit']['destination'] variables, the $url for the header() will be taken from it. So, we have to delete those variables before drupal_goto() call. It can be performed in the button's submit handler (uc_product_save_continue_submit()):

unset($_REQUEST['destination']);
unset($_REQUEST['edit']['destination']);

P.S. This simple solution has one disadvantage: the "destination" param will FINALLY disappear from the URL, so it will be impossible to push default Save button to return to the original "destination" URL. This problem can be solved with the help of the hook_exit() (see drupal_goto()) - we have to backup the original "destination" in the uc_product_save_continue_submit() and then restore it in the hook_exit().

longwave’s picture

I think I understand what you mean, but not sure about your hook_exit implementation - if you can provide a patch that would help get this feature included.

shp’s picture

StatusFileSize
new2.93 KB

See the patch attached. It's my second patch for Drupal and unfortunately I have no time to play with GIT at this moment, so please try to apply it. Any comments are welcome :)

P.S.

1. Perhaps these modules implement the same functionality:
http://drupal.org/project/save_edit
http://drupal.org/project/mb
(I haven't tested it, just read the descriptions)

2. In D7 this patch will be simpler.

longwave’s picture

Status: Active » Needs review

Patch looks good, and incredibly well commented - I just need time to test it.

Status: Needs review » Needs work

The last submitted patch, save_and_edit_destination.patch, failed testing.

longwave’s picture

Version: 6.x-2.4 » 6.x-2.x-dev
Status: Needs work » Needs review
shp’s picture

1. Small improvement - unset($_REQUEST['edit']['destination']); changed to

if (isset($_REQUEST['edit']['destination'])) {
  unset($_REQUEST['edit']['destination']);
}

(see comments).

2. I've installed a git-client and created patch from it. Hope, that the patch will pass the tests...

shp’s picture

No "#" in the filename...

shp’s picture

longwave, why this patch cannot be tested automatically? Unfortunately, it wasn't released in the yesterday's 6.x-2.6 version...

P.S. I'm going to port it to D7-branch.

Status: Needs review » Needs work

The last submitted patch, 1197010-save_and_continue_destination-(2).patch, failed testing.

tr’s picture

@shp: If you click on "View details" in #10, you will see that the testbot reports that your patch is in an invalid format, and tells you to "Ensure the patch only contains unix-style line endings."

I also think that using hook_exit() should be avoided at all costs, because it has impact on caching. Any patch which creates a new implementation of hook_exit(), like this one does, is going to need testing under a variety of circumstances to ensure that a little fix like this doesn't cause a major unintended behavior difference.

longwave’s picture

Priority: Normal » Minor

Marking as "minor" because this only has a very small number of use cases that I can see.

Can we just get away with a simpler implementation of unsetting $_REQUEST['destination'] in the submit handler, and not using hook_exit()? This means that ?destination URLs will be lost when using Save & continue, but that's an even more minor problem than the original issue here.

If we do go with this method:

+  // Determine if the Destination is an absolute URL or not (see drupal_goto()).
+  $colonpos = strpos($destination, ':');
+  $absolute = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($destination, 0, $colonpos)));
+
+  // If it is absolute, we will not take the Destination back to the URL -
+  // thus, we don't need to backup it. Otherwise we backup it.
+  if (!$absolute) {
+    $GLOBALS['destination_backup'] = $destination;
+  }

Why bother duplicating the work that drupal_goto() does? Just back up the destination as provided, and let drupal_goto() perform sanity checks on it when it will actually be used.

longwave’s picture

Also, when is $_REQUEST['edit']['destination'] actually used instead of just $_REQUEST['destination']? I can see core deals with this case, but do we need to handle it here as well?

hanoii’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Category: Feature request » Bug report
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new696 bytes

I just needed to fix this, attached is a patch for D7, haven't really reviewed the other patches but as there were complains and they fail tests, mine is really a simple one.

Also something very similar can be done for D6, but slightly different. I stumbled upon with this useful post that allowed me to work out this patch very nicely: https://drupal.org/comment/4792980#comment-4792980

EDIT: I also change it to a minor "Bug" because of what you'd expect from the "Save and continue" button.

hanoii’s picture

Title: "Save and continue" button: make the URL param "destination" have no influenece when pressing this button » "Save and continue" button doesn't work when destination URL parameter is set

EDIT: Cleared because I really wanted to update the Issue summary. Will do that now.

hanoii’s picture

Issue summary: View changes
hanoii’s picture

Bumping this easy fix, still applies to 3.8.