How is it possible to get the URL of the content where the user was when s/he flagged an entity? I have content in a view in which I have the links to flag the entities so the URL where the entity is flagged is not the one of the entity itself as available in $account

I've tried this snippet to get the arg() of the page but as I thought, the arg() is related to the flagged entity.

function MYMODULE_flag($flag, $entity_id, $account, $flagging) {
  if ($entity_id->fid == FID && $flag == "flag"){
  • Without altering the flag module I'm pretty sure that isn't possible. At a pinch you could try inspecting $_SERVER['HTTP_REFERRER'], but that's not a bulletproof method by any stretch
    – Clive
    Commented May 22, 2013 at 13:04
  • you should be able to set the flag link type to a javascript toggle. Thus, you wouldn't be leaving your views page to actually do the flagging when clicking on it and arg() should then be that of the views page. Of course, if you want to end up on the flagged content (user I am assuming given $account mentioned above) you could do some fancy drupal_goto() in your module's flag hook if arg() was the view page :)
    – Jimajamma
    Commented May 22, 2013 at 13:48
  • @Clive $_SERVER['HTTP_REFERRER'] appears to be empty when using the dpm() in the above function...
    – jozi
    Commented May 22, 2013 at 15:47
  • I guess your flag uses AJAX then?
    – Clive
    Commented May 22, 2013 at 15:48
  • 2
    Blasted Americanisation of the wonderful English language - PHP uses $_SERVER['HTTP_REFERER'] (one 'r') instead of the (IMHO) correct spelling. But that header is optional and some browsers simply won't send it. Without changing the flag module's JS to pass back the current URL I can't think of a way around this
    – Clive
    Commented May 22, 2013 at 16:01


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.