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.
When url() and l() were changed to use an options array, drupal_goto() was not modified to use this same format. This causes confusion when the expectation is that drupal_goto will accept the same parameters as url().
Comment | File | Size | Author |
---|---|---|---|
#18 | drupal.goto-args.patch | 11.48 KB | sun |
#16 | drupal_goto_d7-16.patch | 11.42 KB | kwinters |
#9 | drupal_goto_d7.patch | 4.03 KB | kwinters |
#5 | drupal_goto.patch | 4.99 KB | drawk |
#1 | drupal_goto.patch | 5 KB | jgoldberg |
Comments
Comment #1
jgoldberg CreditAttribution: jgoldberg commentedHere is a patch that takes a stab at this. However, I'm not quite clear whether you expect the same $options array to be interchangeable between url(), l(), and drupal_goto(). drupal_goto takes a distinct set of parameters from that of url() and l(). Regardless, I think we should follow the standard of using associative $options arrays rather than long parameter headers.
Comment #2
lilou CreditAttribution: lilou commentedPatch no longer applied.
Comment #3
drawk CreditAttribution: drawk commentedTempted to reroll this, but have the same question as jgoldberg. Certainly for consistencies sake, having drupal_goto take its argument(s) as an associative array makes sense, but is the intent broader than this? Is the expectation that drupal_goto will somehow take an associative array with similar elements, or just that it will take an associative array?
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commented@drawk: the only irrelevant parameter is $absolute. All other parameters for url() are the same, we just need to add 'http_response_code'.
Comment #5
drawk CreditAttribution: drawk commentedHere's a reroll that applies cleanly. Still needs work, though. I found a problem in the original patch - specifically the following bit in form.inc
The first argument is still expected to be a string, so this always redirects you to www.example.com/Array when submitting forms and such ('Array' because of the array to string conversion). In the attached patch, I changed this to
Which at least gets you to the desired destination page, and without errors, but obviously you lose any additional parameters.
Comment #6
webchickTagging.
Comment #7
sunsubscribing
Comment #8
sunTagging absolutely critical clean-ups for D7. Do not touch this tag. Please either help with this or one of the other patches having this tag.
Comment #9
kwinters CreditAttribution: kwinters commentedMuch more recent reroll plus a variety of improvements attached.
The main thing I haven't decided on yet is whether to do:
which seems cleaner and more sensible but means altering like $args['options']['http_response_code'] = 500; or something like:
which is backward compatible with all the $args['http_response_code'] = 500; etc. code already in place and is flat.
The tests won't pass until that's resolved.
Comment #10
sunPlease read http://drupal.org/node/1354 on proper formatting of Doxygen lists.
$http_response_code needs to stay a separate argument.
'absolute' must be forced to TRUE, so it must be assigned after the destination has been parsed.
You can simply array_merge($options, $destination) here, because 'path' doesn't matter for url().
Unless you want to alter some further places throughout core, I wouldn't necessarily change this alter hook.
But if you do, then I really wonder why we pass that stuff so strangely.
drupal_alter('drupal_goto', $path, $options, $http_response_code);
will do. The previous munging into an array was only done, because we had to pass multiple arguments....
ugh. Now I realize that you can't do what I propose until #593522: Upgrade drupal_alter() lands. :-/
This review is powered by Dreditor.
Comment #11
kwinters CreditAttribution: kwinters commented* "$http_response_code needs to stay a separate argument."
I'm not sure why this is true. Is this a precedent set somewhere, etc.?
* "'absolute' must be forced to TRUE, so it must be assigned after the destination has been parsed."
My thought was that anything passed in should be possible to alter. If that shouldn't be the case, I'll set it after the alter comes back so it doesn't imply that it can be changed.
* "You can simply array_merge($options, $destination) here, because 'path' doesn't matter for url()."
I was doing that at first, and then stopped. There are exactly 3 parts to the array $destination, and path has to be treated special regardless. Since there are only two left, I opted to handle them individually rather than risk any (somewhat unlikely) side effects.
* drupal_alter
For now I'm just going to shoot for backward compatibility, and if the drupal_alter issue gets committed I'll set it to use drupal_alter('drupal_goto', $path, $options, $http_response_code); or something equivalent.
Comment #12
sun#593522: Upgrade drupal_alter() is in now, so you can use the much more readable and usable way of multiple arguments instead of a totally strange $args argument. :)
I really hope we get this done ASAP. Please also do not forget that we may need changes in drupal_redirect_form() according to what we do here.
Comment #13
sun1) The response code does not belong to url() arguments, and the goal here is to make the primary arguments of drupal_goto() consistent with url(). The response code is an additional, special argument for drupal_goto().
2) 'absolute' must always be TRUE, because the generated URL is used as Location HTTP header. Partially also required for SimpleTest.
3) Actually, it doesn't matter, I just would find it cleaner.
4) Clarified in #12 - it's much cleaner to pass meaningful variable names (which, again, are consistent with drupal_goto()) instead of a clumsy $args array, which you need to read docs for first to understand what's in.
Comment #14
XanoComment #15
sunComment #16
kwinters CreditAttribution: kwinters commentedSome code was moved around because of the drupal_exit commit earlier today, and the drupal_alter patch makes the function much cleaner.
The form.inc lines in #5 didn't work because 'redirect' needed to use the new drupal_goto format where it was used with multiple parameters, now resolved without changing form.inc (4 places).
All *_drupal_goto_alter functions changed to use the new args (2 places, both were tests).
Anywhere that called drupal_goto directly AND previously used more than just $path changed (openid only).
Documentation cleaned up some ($path and $http_response_code unchanged, $options pulled from url() minus absolute, other minor cleanup).
System.api.php sample hook updated.
Comment #18
sunThis should get us somewhere past the installer.
Comment #19
kwinters CreditAttribution: kwinters commentedI see that you added some type hinting. Any other changes?
Comment #20
sunyes, the changes to includes/batch.inc are the trick to make this pass the installer ;) Also, I've corrected some more instances of $form_state['redirect'].
So, actually, this should be ready to fly.
Comment #21
merlinofchaos CreditAttribution: merlinofchaos commentedLooks good to me!
Comment #22
kwinters CreditAttribution: kwinters commentedRTBC seconded, looks good.
Comment #23
webchickCommitted to HEAD!
Needs documenting in the upgrade guide.
Comment #24
jhodgdonJust closed #609922: missing documentation for changes to $form_state['redirect'] structure as a duplicate of this issue...
This change does still need documentation in the upgrade guide, and that other issue gives some guidance as to part of what needs to be documented...
Comment #25
sunAdded docs to http://drupal.org/node/727352
Comment #26
jhodgdonAdding docs to a "More..." page does not fix the issue. It needs to be added to the upgrade page. http://drupal.org/update/modules/6/7
Comment #27
jhodgdonupdating tagging scheme
Comment #28
jhodgdonActually, it looks like that aux page has been incorporated into the main page.