In confirmation forms generated by confirm_form :
The "cancel" redirection link can only be set with a drupal path, without querystrings or fragments.
This for instance causes this behaviour :
- on admin/node, go to page 2
- check a node and "delete" it
- on confirmation, click cancel
- you're back on admin/node page 1 (and not page 2)
The attached patch accepts cancel destinations in the form :
foo/bar/baz?arg1=value&arg2=other#fragment
(as generated by drupal_get_destination...)
It does not alter the "admin/node deletion cancelled" decribed above (that's a mere example), but provides the needed functionnality to do so...
Comments
Comment #1
yched commentedstatus...
Comment #2
yched commentedre-rolled against current cvs
Comment #3
moshe weitzman commentedworks as advertised
reroll to remove fuzz
Comment #4
dries commentedCommitted to CVS HEAD. Thanks.
Comment #5
Steven commentedThis patch is horribly broken. We do not overload menu paths with an extra syntax like this. Paths that includes '?' ':' or '#' cannot be used as confirm destinations after this patch.
Perhaps a more sensible solution is to move towards passing in destinations as keyed arrays (e.g. 'path', 'query', 'fragment') and treat string destinations are pure paths. This is backwards compatible and doesn't introduce on forbidden characters.
Comment #6
yched commentedI'm not sure I get your reservations, but I'll take you word on it.
Here's a patch against current 5.0 code, (since my previous patch got in), that uses the approach you propose (the text documenting the parameter could probably be enhanced).
Comment #7
yched commentedComment #8
dries commentedI rolled back to patch but don't like the patch proposed in #6 either.
Comment #9
yched commentedAlright - any hint on what is wrong ? coding style ? the array argument ? the whole idea ? I still think the example I provided in my original post above about admin/node is a usability issue...
Anyway, here's the patch in #6 rerolled and more secured.
Comment #10
Steven commentedyched's: The rerolled patch is missing?
I think the idea of passing in destinations as arrays has lots of promise. Many functions are now bogged down by having to include $path, $query, $fragment as arguments, even though they are rarely used. With the proposed solution, they can all be replaced by a single $destination argument, which takes a path string, or a keyed array (path, query, fragment). We could even allow query to be an array too, and transparently perform query string encoding.
It also matches with the principle of keeping data in the most natural form (i.e. a structured array of plain text) rather than baked into an encoded string (i.e. a URL).
Comment #11
drummLooks like an API change now.
Comment #12
yched commented@Steven : Er, right. Here it is.
@drumm : It is not an actual API change - no compatibility break, existing calls to confirm_form remain unchanged.
The purpose here is a usability enhancement (have 'op cancel' work well with paged lists), so I think this is still for 5.0.
Comment #13
drummNULL should always be uppercased.
$query and $fragment will need to be initialized to something or not used if $path isn't an array().
Comment #14
yched commentedupdated per drumm's comments
Comment #15
yched commentedand the patch.
Comment #16
RobRoy commentedThe third default arg sould be array(), not NULL for l().
Also, I think we should be consistent with _submit handler return values that just return a non-associative array like return array('pathval', array(), 'queryval', 'fragval'); not array('path' => 'pathval', ...); or did that change in 5.x?
Comment #17
yched commentedThat did not change in 5.0 - but that is not (or completely) documented :
the doc for drupal_submit_form reads
"@return : A string containing the path of the page to display when processing is complete."
The non-associative way seems less clean. It's sort of ok for hook_submit return values because
they are fed directly to drupal_goto with
call_user_func_array('drupal_goto', $goto);We can't do this here, so it means code like :
which seems awkward. Plus what would we put in the doc for the $path parameter ?
'a drupal path as à string, or an array in the form array('drpath', array(), 'query', 'fragment').
Not nice. The little consistency we gain does not balance that IMO.
I tend to agree with Steven in comment #10 above : we should move the other way around and
generalize (in drupal 6) 'paths as associative array' in the l / drupal_goto / hook_submit / etc functions
NULL default value : right - attached patch corrects this.
Comment #18
RobRoy commentedYeah, I agree with the associative array. You're right. IMO we should make this consistent the other way then and have associative arrays returned from _submit() FAPI callbacks. Issue for that at http://drupal.org/node/100730.
Comment #19
moshe weitzman commentedi'd like to see one instanced of this in the patch so we know that the new syntax works.
Comment #20
yched commentedEr, there was a typo my in #17 patch ($path['$path'] instead of $path['path']).
Here it is re-rolled.
Comment #21
yched commentedAnd per moshe's request, here is an _example_ use case, as a patch for node.module
It implements a fix for the behaviour I described in my original message in this thread
(let the user get back to the right page if he cancels a delete operation on admin/content/node)
To test this, you naturally need to have enough nodes, so that admin/content/node is paged...
Please note : of course this is for demonstration only - it might be not be the right and clean way to do this.
If and when the confirm_form patch is committed, I'll submit a proper patch for review (for this and for the related user and comments delete operations).
Comment #22
yched commentedComment #23
Steven commentedI committed #20 to HEAD. Yes it's an API change, but better than the alternative, and a useful ability to have.
We need to look at the confirm forms in core and see if we need to include a query string. However, the propsed example uses icky stuff like substr(..., 12) which is weird. I suggest you open up another issue if this is important, and link it here.
Comment #24
(not verified) commentedComment #25
moshe weitzman commenteddid anyone fix the rest of the forms for this new syntax?