function set_user_permissions in Patterns 7.2
Wraps the call to drupal_form_submit for 'user_profile_form'. Gathers all the expected values from the form and prepare them for the query.
Parameters
string $form_id String containing the form ID. In the case of custom functions the value is empty.:
array $form_state Set of values after parsing the action.:
1 string reference to 'set_user_permissions'
- user_patterns in patterns_components/
components/ user.inc - Implements hook_patterns() for the user module.
File
- patterns_components/
components/ user.inc, line 598
Code
function set_user_permissions($form_id, &$form_state) {
//Transform the rolename into a role object, we don't need to check existance since we did it previously
$role = user_role_load_by_name($form_state['values']['role']);
//Prepare all the attributes for the query, but uid
$permissions = $form_state['values']['value'];
//Remove all permissions not associated to any module (due to http://drupal.org/node/737816)
$modules = user_permission_get_modules();
foreach ($permissions as $key => $name) {
if (!isset($modules[$name])) {
unset($permissions[$key]);
}
}
patterns_set_user_permissions($role->rid, $permissions);
$msg = t('Permissions for role %role successfully updated.', array(
'%role' => $role->name,
));
return patterns_results(PATTERNS_SUCCESS, $msg);
}