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.
To reproduce: create a paged view with a flag link field, and enable AJAX for the view. After paging via ajax, flag links will function, but redirect to /views/ajax instead of the view path.
Comment | File | Size | Author |
---|---|---|---|
#4 | flag-redirect_to_parent_path-2849217-4.patch | 1.6 KB | acrollet |
#2 | flag-redirect_to_parent_path-2849217-2.patch | 1.47 KB | acrollet |
Comments
Comment #2
acrollet CreditAttribution: acrollet commentedpatch attached - this patch attempts to get the parent path from the referrer if the redirect path is 'views/ajax'. It only replaces the destination if the referrer path resolves to an internal URL.
Comment #3
joachim CreditAttribution: joachim as a volunteer commentedThanks for taking the time to figure this out!
We shouldn't hardcode Views. Partly because we don't depend on Views, but mostly because there may be other similar situations where a flag link is loaded over AJAX.
What is it about this situation that we can generalize? For instance, can get look at the current route object and detect that it's AJAXy, and use that as the condition here instead?
BTW, this patch will clash with #2732065: Flag links redirect to the system path rather than the actual path the user was on.
Comment #4
acrollet CreditAttribution: acrollet commentedthanks for reviewing! Fair enough, can't say I really know what's generalizable in terms of detecting AJAXy-ness, but how about this approach?
Comment #5
joachim CreditAttribution: joachim as a volunteer commented> can't say I really know what's generalizable in terms of detecting AJAXy-ness,
What I was wondering is whether the actual Route object tells you whether it returns HTML or AJAX.
Comment #7
acrollet CreditAttribution: acrollet commentedHere's a Route object, no smoking guns that I see:
If we could get the Response, we could theoretically see if it's an instance of AjaxResponse and be in business, but I haven't been able to dig up a way to get the current response.
Comment #8
csedax90 CreditAttribution: csedax90 commented#4 works for me
Comment #9
csedax90 CreditAttribution: csedax90 commentedComment #10
joachim CreditAttribution: joachim as a volunteer commented> If we could get the Response, we could theoretically see if it's an instance of AjaxResponse and be in business
Indeed. Though does that exist yet at this point?
Does Drupal::request() tell us anything?
Comment #11
kerasai CreditAttribution: kerasai at net2Community, Inc. commentedI believe this is a duplicate of #2846111: AJAX link not working when used in views, which has a patch but appears to not be merged yet due to a lack of test coverage.