Problem:
When a new node is being created, if there's a destination set, the "Save and Add another" button won't work. The user is redirected to the page given in the destination instead.

Repeatable: Always
Steps to repeat:
- Add a node with destination set: ?destination=foo/bar

Comments

danielfdsilva’s picture

Title: URL query parameters when using "Save and Add another" button » Patch
Status: Active » Fixed
StatusFileSize
new2.02 KB

I found out that this happens because the drupal_goto() function gives priority to the destination if it's set.

I fixed the problem by unsetting the destination but in our project we needed to be able to add multiple content while keeping the destination parameter for later use.

To accomplish this I modified the module creating a customizable option that allows us to keep the destination and other query params as well.
This option is content-type specific and it's not set by default cousing the destination parameter to be discarded.

This is my firt collaboration with the drupal comunity. If you have some comments or tips i'll appreciate.

danielfdsilva’s picture

Title: Patch » URL query parameters when using "Save and Add another" button
danielfdsilva’s picture

Status: Fixed » Needs review
sokrplare’s picture

Status: Needs review » Reviewed & tested by the community

Works beautifully - saved me some time for a client project - thanks!

Only thing to tweak is switching to use double-spaces instead of tabs per Drupal Coding Standards. I've set this to RTBC though so it can get committed and hopefully something that minor can just be tweaked as it gets committed - or if you can resubmit with tabs switched to spaces that would be ideal!

robin monks’s picture

Status: Reviewed & tested by the community » Needs work

This does look good; and thanks for the patch Daniel! That said, with something like this it needs a test added. For information on writing tests check out http://drupal.org/simpletest and the existing addanother.test file.

/Robin

danielfdsilva’s picture

StatusFileSize
new2.19 KB

I changed the tabs to double spaces like covenantd said.
As for the test, I had a quick look at the docs and it didn't seem easy. I need to read a bit more.

Anyway, here's the patch.

sokrplare’s picture

@danielfdsilva - yeah, the test framework scares me too :)

I'm wondering if the code added to the node_clone_onsave_node_form_submit functions should be moved into _node_clone_onsave_node_clone_path so it will be picked up by theme_node_clone_onsave_message_message as well?

As a sidenote, I've just spent an hour and ported this code pretty directly over into a node_clone_onsave module I'm putting in my sandbox (http://drupal.org/sandbox/covenantd/1866074) and either will add as a patch to the clone module (#1866082: Patch or standalone module for Node Clone on Save button), or as a standalone module.

koppie’s picture

Unfortunately the patch loses the destination url if you click "add another."

danielfdsilva’s picture

@koppie
When configuring addanother, you have an option to keep the query params (last option).
Isn't that what you want? :)

nwom’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

It works perfectly. The destination querystring works as well.

Thank you very much for the patch!

nwom’s picture

Status: Reviewed & tested by the community » Needs work

Ah didn't realize the tests still had work. Changing the status again.

Also, just found out that the button works perfectly, however the "Display the Add another message after node creation. " does not include the query parameters.

lunk rat’s picture

Thanks @danielfdsilva for the patch in #6! It works perfectly a destination URL is provided (as long as I configure the content type to preserve URL parameters)

Note: this patch is based on Drupal site root directory (it should be based on addanother module root directory).

pianomansam’s picture

Version: 7.x-2.x-dev » 7.x-2.2
StatusFileSize
new1.67 KB

Patch in #6 doesn't work when a $_GET param is an array. Is is an updated patch that uses Drupal's url() function to correctly pass along the $_GET params. Also note that this patch it to 7.x-2.2 as 7.x-2.x-dev has changed drastically.

david.qdoscc’s picture

#13 works great for me. Thanks!

robin monks’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
Assigned: Unassigned » robin monks
Status: Needs work » Needs review
StatusFileSize
new2.25 KB

Changed the logic as there really isn't a point to having a setting for telling Add Another to do the right thing, so now if there's a destination it's saved between adding nodes and enforced at the end. Also added tests for this. This will make its way into 2.x-dev, but is here for any input needed.

robin monks’s picture

Status: Needs review » Fixed

This has landed on 7.x-2.x.

  • 58e1286 committed on 7.x-2.x
    Issue #1833508 by danielfdsilva, Robin Monks, pianomansam: URL query...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

marassa’s picture

(sorry, never mind)

david.qdoscc’s picture

I think this issue needs reopening. #13 still behaves correctly for me, whereas #15 only kept the destination parameter, but dropped other query parameters (I am using multiple parameters to prepopulate fields, along with the destination parameter). Perhaps more testing is required?

Sorry - just seen this is now a separate issue: #2850821: Query parameters apart from "destination" are removed when clicking "Add Another"