hey guys, i think this is a core bug; bug i only see it showing up with pathauto so far so i'll report it here and perhaps you guys will have a better idea if this is a core bug or not (and maybe a little more clout to get it fixed).
i am using the token [user:roles:first] (although i am sure all role based tokens are affected) for defining urls for users as [user:roles:first]/[user:field_firstname]-[user:field_lastname]
an example resulting alias for a user in role "faculty" is: 4/melanie-smith
4 = faculty
the issue is that $form-state['user']['roles'] starts out like:
2 => authenticated-user
4 => faculty
but it hits this function: entity_form_submit_build_entity() and gets modified to:
array =
4: string = 4
2: bool = TRUE
3: long = 0
5: long = 0
6: long = 0
7: long = 0
i am not completely sure; but this gets busted at the call in common.inc at line 7679:
$values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $bundle)) : $form_state['values'];
which i think is meant to remove form state values which should not get modified. and $user or $user->roles should likely be in there.
just as a quick test, i removed $user->roles from this array and i then get my url as authenticated-user/melanie-smith (which isn't quite right either; but i closer)
Comment | File | Size | Author |
---|---|---|---|
#5 | 1297528-role-data-not-consistent.patch | 1.34 KB | Dave Reid |
Comments
Comment #1
liquidcms CreditAttribution: liquidcms commentedmoving to Tokens
Comment #2
liquidcms CreditAttribution: liquidcms commenteduntil this code gets fixed either in token or in core; here is code for a new custom token for the user's role.
as can be seen in the code, further evidence that this is likely a core bug, the user object has different values for $user->role depending on if editing a user directly or if doing a bulk change of user's url alias.
Comment #3
Dave ReidCould you please elaborate on how or what you are doing causes the $account->roles data to become non-standard?
Comment #4
Dave ReidAh, I see now - it happens when editing an existing user at user/uid/edit.
Comment #5
Dave ReidPlease try the following patch to token module.
Comment #6
Dave ReidCommitted #5 with a test to 7.x-1.x: http://drupalcode.org/project/token.git/commit/58b295c
Comment #7
liquidcms CreditAttribution: liquidcms commentedyup, the role token seems to work now. still will need my custom token however as don't want authenticated to always be the role i get for a user.
also, since i still need my code to check if what format the $user->roles value is in; i would still think there is a core bug here somewhere.
like your array_intersect_key(user_roles(), $account->roles); method though.. :) better than what i did