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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acrollet created an issue. See original summary.

acrollet’s picture

patch 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.

joachim’s picture

Status: Needs review » Needs work

Thanks for taking the time to figure this out!

+++ b/src/ActionLink/ActionLinkTypeBase.php
@@ -152,13 +154,24 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
+    // being built during a views AJAX request.
+    if ($current_path == 'views/ajax') {

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.

acrollet’s picture

thanks for reviewing! Fair enough, can't say I really know what's generalizable in terms of detecting AJAXy-ness, but how about this approach?

joachim’s picture

> 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.

Status: Needs review » Needs work

The last submitted patch, 4: flag-redirect_to_parent_path-2849217-4.patch, failed testing.

acrollet’s picture

Here's a Route object, no smoking guns that I see:

<pre>stdClass Object
(
    [__CLASS__] => Symfony\Component\Routing\Route
    [path] => /views/ajax
    [host] => 
    [schemes] => Array
        (
        )

    [methods] => Array
        (
            [0] => GET
            [1] => POST
        )

    [defaults] => Array
        (
            [_controller] => \Drupal\views\Controller\ViewAjaxController::ajaxView
        )

    [requirements] => Array
        (
            [_access] => TRUE
            [_method] => GET|POST
        )

    [options] => Array
        (
            [compiler_class] => \Drupal\Core\Routing\RouteCompiler
            [_route_filters] => Array
                (
                    [0] => method_filter
                    [1] => content_type_header_matcher
                )

            [_route_enhancers] => Array
                (
                    [0] => route_enhancer.param_conversion
                )

            [_access_checks] => Array
                (
                    [0] => access_check.default
                )

        )

    [compiled] => stdClass Object
        (
            [__CLASS__] => Drupal\Core\Routing\CompiledRoute
            [fit] => 3
            [patternOutline] => /views/ajax
            [numParts] => 2
        )

    [condition] => 
)

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.

csedax90’s picture

Issue summary: View changes

#4 works for me

csedax90’s picture

Issue summary: View changes
joachim’s picture

> 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?

kerasai’s picture

I 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.