Hi!
I'm a newbie in php but by searching and reading in drupal.org I've managed to create my php snippet for login destination. It works fine.
Looks something like this:

global $user;
if (in_array('role1', $user->roles)) {
    return 'node1';
}  
if (in_array('role2', $user->roles)) {
    return 'node2'; 
}else {
    return '<front>';
}

Now, what i want to do is to redirect a user with more than one role. For example, I want that user with only role1 or only role2 assigned be redirected to the correspondent node, but I want that a user that has been assigned with role1 and role2 be redirected to another node, say node3.
I've tried to add to the code above:

if (in_array('role1', $user->roles)) && if (in_array('role2', $user->roles))  {
    return 'node3';
}  

and later

if (in_array('role1', $user->roles)) AND if (in_array('role2', $user->roles))  {
    return 'node3';
}  

but i'm having no success, it keeps redirecting user with two roles to frontpage.

Probably this is a super simple question, perhaps syntax related but i don't understand much of php...

Comments

margaridacarvalho’s picture

Assigned: margaridacarvalho » Unassigned
rsvelko’s picture

Status: Active » Fixed

the if syntax uses only one "if" - this is the right way:

(whether u use && or AND affects only the precedence/priority of operations which does not matter most of the time )

if ( in_array('role1', $user->roles) && in_array('role2', $user->roles)  ) {
    return 'node3';
} 

This should work.

I include it into the snippets library - displayed in the admin UI in the next version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.