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.
Problem/Motivation
Redirecting a modal form that is overlayed on path 'node/1' to path 'node/1#comment-37' using the ctools_ajax_command_redirect() function leaves the modal up.
Proposed resolution
No workarounds or proposed solutions yet.
Remaining tasks
Workarounds and solutions to be submitted and reviewed.
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedYou need to be more specific. How are you redirecting?
Note that browsers, when you give the SAME URL and only change the fragment, do not actually change locations. So if you're using the ctools_ajax_command_redirect command, and this is the behavior you get, that is standard browser behavior. If that's what you're doing, what you'll actually need to do is a reload, or to rerender what you need and dismiss the modal and then redirect.
Comment #2
jantoine CreditAttribution: jantoine commented@merlinofchaos,
I was indeed using the ctools_ajax_command_redirect command. I figured it was defaulting to browser behavior, but with the modal being present, wasn't sure if ctools should be responsible for cleaning that up first. I have used a reload, but that doesn't include a hash to the latest comment that has been added. I will try the re-render approach.
Comment #4
j0rd CreditAttribution: j0rd commentedI have the same "feature".
Here's why it looks like a bug. IMHO it should force a reload to avoid problems.
Load a comment form in a modal, while browsing a node which lists is comments. Then submit a comment from the modal and ctools_ajax_commend_redirect() to /node/NID#comment-1234 . Normally in Drupal, this would be done via a 301 header redirect and things would work as expected, but with ctools redirect it's just closing the modal and trying to bump the browser down to #comment-1324, which doesn't exist until the page reloads.
I believe most devs (correct me if I'm wrong) would expect ctools_ajax_command_redirect() to work more like a PHP header 301, instead of mimicking "hitting a link", which is currently what it's doing.
Feel free to re-close this if you think it's still not a bug.
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedI don't know why you'd expect that. It's simply browser behavior, and it acts the way it does. Your code probably needs to actually render the new comment before issuing the redirect, and then all will be well.
Comment #7
kle CreditAttribution: kle commentedMy workaround/solution to redirect and jump to an anchor:
The redirect I've put in a function:
and hook_init redirects again - this time to the anchor:
Comment #8
4alldigital CreditAttribution: 4alldigital commentedto anyone that comes across this like me... useful info above but wanted to share my workaround also:
with a changing 'timestamp' seems to trick the browser into refreshing current page with fragment.
Comment #9
shabana.navas CreditAttribution: shabana.navas at Cheeky Monkey Media commentedI still agree with the others and think this is a bug. I've had the same problem as j0rd in comment #4, where I have a feature to add comments through a ctools modal. I wanted to reload the page and then jump the user to the newly created comment. Obviously, with using, ctools_ajax_command_reload();, it'll just reload the page. But the behavior I expected from ctools_ajax_command_redirect(), was that it would go the url that I specify and then, after including a fragment, jump to the newly created comment. But it's not reloading the page.
Redirect, in essence means, go to a certain page right? So, after a comment is saved, we're saying go to a certain page, and jump to a particular fragment. It's not reloading/redirecting, just jumping to the fragment, so that's essentially a bug.