0

I`ve set up a Rule to redirect a user after log in. The Rule works redirecting the user to the URL specified, but it doesn't contain all the query parameters after "?".

This is the URL value:

user/login?destination=node/4?cid1=[entity-fetched-household:0:contact-id]&cs1=[entity-fetched-household:0:hash]&cid2=[account:civicrm-contact:contact-id]&cs2=[account:civicrm-contact:hash]

But the user is redirected to the following one:

user/login?destination=node/4?cid1=[entity-fetched-household:0:contact-id]

just containing the first query parameter cid1.

I've checked the other parameters, cs1, cid2, cs2, contain the correct values.

This is the export of the Rule:

{ "rules_add_parameters_to_url_related_to_contact_id" : {

"LABEL" : "Add parameters to url related to contact id",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "path" ],
"ON" : { "user_login" : [] },
"DO" : [
  { "entity_query" : {
      "USING" : {
        "type" : "civicrm_contact",
        "property" : "display_name",
        "value" : [ "account:civicrm-contact:household-name" ],
        "limit" : "1"
      },
      "PROVIDE" : { "entity_fetched" : { "entity_fetched_household" : "Fetched entity" } }
    }
  },
  { "redirect" : { "url" : "user\/login?destination=node\/4?cid1=[entity-fetched-household:0:contact-id]\u0026cs1=[entity-fetched-household:0:hash]\u0026cid2=[account:civicrm-contact:contact-id]\u0026cs2=[account:civicrm-contact:hash]" } },
]
  }
}

Any help will be really appreciated.

0

That's the way drupal_parse_url() parses your URL. If you think this is wrong, you can escape your & characters and file an issue in the core Drupal issue queue.

$ drush php-eval 'print_r(drupal_parse_url("user/login?destination=node/4?cid1=[entity-fetched-household:0:contact-id]&cs1=[entity-fetched-household:0:hash]&cid2=[account:civicrm-contact:contact-id]&cs2=[account:civicrm-contact:hash]"));'
Array
(
    [path] => user/login
    [query] => Array
        (
            [destination] => node/4?cid1=[entity-fetched-household:0:contact-id]
            [cs1] => [entity-fetched-household:0:hash]
            [cid2] => [account:civicrm-contact:contact-id]
            [cs2] => [account:civicrm-contact:hash]
        )

    [fragment] => 
)
  • Just to clarify: would I need to implement a hook to change the behavior of the function drupal_parse_url()? At the moment I have never worked to extend or alter the core behavior of Drupal. Could you quickly guide me where I should implement this change in the Drupal core functionality? – Cristina P. Feb 7 at 10:10
  • No hook needed. drupal_parse_url() sees your URL as user/login followed by ? followed by a bunch of key=value pairs separated by &. So it's parsing destination= , cs1=, cid2=, cs2=. But that's not what you intended - you intended those key=value pairs to be part of the destination. How is drupal_parse_url() supposed to know that? I would have to look at the RFC to be sure, but I think drupal_parse_url() is doing the correct thing here. The way you can force it to do what you want is to escape the & symbols so drupal_parse_url() doesn't see them as &. To do this, simply replace them with %2c. – anonymous Feb 8 at 6:31
  • $ drush php-eval 'print_r(drupal_parse_url("user/login?destination=node/4?cid1=[entity-fetched-household:0:contact-id]%2ccs1=[entity-fetched-household:0:hash]%2ccid2=[account:civicrm-contact:contact-id]%2ccs2=[account:civicrm-contact:hash]"));' Array ( [path] => user/login [query] => Array ( [destination] => node/4?cid1=[entity-fetched-household:0:contact-id],cs1=[entity-fetched-household:0:hash],cid2=[account:civicrm-contact:contact-id],cs2=[account:civicrm-contact:hash] ) [fragment] => ) – anonymous Feb 8 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.