1

I have a rule that redirects a user when visiting a view. But it does not work with the event "view page" or "Drupal is initializing".

Here is the rule:

{ "rules_uid_141" : {
"LABEL" : "uid=141",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "redirect manager" ],
"REQUIRES" : [ "rules", "pathrules" ],
"ON" : { "node_view--page" : { "bundle" : "page" } },
"IF" : [
  { "data_is" : { "data" : [ "site:current-user:uid" ], "value" : "38" } },
  { "pathrules_checkpath" : { "path" : "team", "operation" : "equals" } }
],
"DO" : [ { "redirect" : { "url" : "team?field_manager_uid=38" } } ]
  }
}

Any suggestions?

1
  • start debugging - start by removing the conditions: does it trigger? if not, your trigger is wrong. If it does, your conditions are wrong, add one, try again - this will narrow down the problem
    – Geoff
    May 21, 2015 at 4:47

1 Answer 1

0

Use 'Drupal is initializing'

To get this to work, you should be able to use the "Drupal is initializing" event (which is NOT shown in the rule included in your question). That will ensure that the rule gets triggered BEFORE the actual content of your "link with view" is shown (otherwise you are too late, it "is" already shown).

Use a 'Regular Expression'

That link that you want to "intercept", should be formatted in some type of regular expression, which you then use as your Rules Condition. So that you have a rule that corresponds to "before showing the actual content of something that matches a specific path ...". After you get that part to work, your Rules Action is probably fine.

Sample rule

Refer to the "Option 1" part of my answer to the question about "How to restrict access to a node via node/12 and allow access via a path like content/sometitle?", which contains this Rule in export format:

{ "rules_check_url" : {
    "LABEL" : "Disallow node/* access",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "node\/\\d+$",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Sorry, URLs like [site:current-page:url] are not allowed around here ...",
          "type" : "error"
        }
      },
      { "redirect" : { "url" : "no_access" } }
    ]
  }
}

Here is some suggested tuning of the above sample to make it work for your case also:

  • machine name and label.
  • replace the node/* by your path of your view (in the "label", and the regular expression).
  • replace the action part of the rule by your action that you have already.

Note: the rule included in your question also shows that you tried to use the Path Rules module, which implements Rules Conditions for checking an URL against a given string for triggering Rules Actions. That module is another interesting add-on module the Rules, but if you just use a regular expression as shown in my answer, you don't need that module for getting your rule to work.

0

Your Answer

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

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