In flag_flag_link(), drupal_get_destination() will return destination=system/ajax instead of the path to the page if flag links are part of an AJAX request.

So instead of

/flag/confirm/flag/signup/18?destination=my-destination

the link href ends up being

/flag/confirm/flag/signup/18?destination=system/ajax

which returns the user to a blank page.

Similar issue for a different module reported here: http://drupal.org/node/1021328
This also seems related: http://drupal.org/node/1181370. Core issue, perhaps?

Comments

osopolar’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev

Seems that in ajax calls the flag module can't use drupal_get_destination() to define the destination.

Workaround 1: Append a destination parameter the ajax-call like q=system/ajax&destination=my-destination. If destination is set it will just be returned by drupal_get_destination().

Workaround 2: Implement hook_flag_link_types() and hook_flag_link() by a custom module and use something different for drupal_get_destination() in hook_flag_link().

I have no good idea how a fix should work. I guess drupal_get_destination() needs to be fixed somehow (i.e. send the current path in the request ... see http://api.drupal.org/api/views/includes!ajax.inc/function/views_ajax/7).

[Edit:] Fix typo.

nagiek’s picture

Hi,

I want to do the same thing over in #1491820: Store drupal_get_destination before the modal sets q. Going to follow your issue as well to see if there are any developments.

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
jamesdixon’s picture

Issue summary: View changes

Here's another hacky workaround stealing views code from the example linked to in #1. I used this in my ajax call before calling flag_create_link()

          // Overwrite the destination so flag_create_link() doesn't send user to
          // an AJAX url
          // @see bug: https://www.drupal.org/node/1352198
          // @see drupal_get_destination()
          $url_parsed = parse_url($_SERVER['HTTP_REFERER']);
          $dest_parsed = $url_parsed['path'] . '?' . $url_parsed['query'];
          $destination = &drupal_static('drupal_get_destination');
          $destination = array('destination' => $dest_parsed);

I also had to include the flag module's js from the ajax success call:

// Load flag link code to power flags
jQuery.getScript(Drupal.settings.basePath + 'sites/all/modules/flag/theme/flag.js');