function workbench_moderation_admin_check_role_form_submit in Workbench Moderation 7.3
Same name and namespace in other branches
- 7 workbench_moderation.admin.inc \workbench_moderation_admin_check_role_form_submit()
Form submit handler for moderation role tests.
File
- ./
workbench_moderation.admin.inc, line 367 - Administrative functions for Workbench Moderation.
Code
function workbench_moderation_admin_check_role_form_submit($form, &$form_state) {
$rid = $form_state['values']['role'];
$role = user_role_load($rid);
$types = array_filter($form_state['values']['types']);
$moderation_task = $form_state['values']['moderation_task'];
$recommended_permissions = workbench_moderation_recommended_permissions($types);
$recommended_permissions = $recommended_permissions[$moderation_task];
// Get a full list of this role's permissions.
$actual_permissions = user_role_permissions(array_filter(array(
$rid => TRUE,
DRUPAL_AUTHENTICATED_RID => $rid != DRUPAL_ANONYMOUS_RID,
)));
// The results of user_role_permissions() are in a nested array:
// array(rid => array("permission name" => TRUE))
// Check each for our recommended permissions.
foreach ($actual_permissions as $permissions) {
$recommended_permissions = array_diff($recommended_permissions, array_keys(array_filter($permissions)));
}
if (empty($recommended_permissions)) {
// All of the recommended permissions were accounted for.
drupal_set_message(t('The @role role should be a qualified @moderation_task.', array(
'@role' => $role->name,
'@moderation_task' => $moderation_task,
)), 'status');
}
else {
// The specified role didn't have some of the recommended permissions. Print a list for the user.
$all_permissions = module_invoke_all('permission');
foreach ($recommended_permissions as $permission) {
drupal_set_message(t('The @role role may need the "!permission_label" permission in order to be a qualified @moderation_task of @types content.', array(
'@role' => $role->name,
'@moderation_task' => $moderation_task,
'@types' => implode(t(' and '), array(
implode(', ', array_slice($types, 0, -1)),
end($types),
)),
// @TODO: Context senstive translation bug
'!permission_label' => $all_permissions[$permission]['title'],
)), 'error');
}
// Provide links to node and moderation permissions.
drupal_set_message(t('View <a href="@node_permissions">node permissions</a> or <a href="@moderation_permissions">moderation permissions</a> for the @role role.', array(
'@node_permissions' => url('admin/people/permissions/' . $rid, array(
'fragment' => 'module-node',
)),
'@moderation_permissions' => url('admin/people/permissions/' . $rid, array(
'fragment' => 'module-workbench_moderation',
)),
'@role' => $role->name,
)), 'error');
// Note that we don't cover all configurations.
drupal_set_message(t('The @role role may be a qualified @moderation_task regardless of these notices if it has liberal overall node and moderation permissions, like "Administer content" and "Bypass moderation restrictions".', array(
'@role' => $role->name,
'@moderation_task' => $moderation_task,
)), 'warning');
}
// Note that we don't cover all configurations.
drupal_set_message(t('You must check manually that this role has the appropriate transition permissions for your workflow. <a href="@moderation_permissions_link">View moderation permissions for this role.</a>', array(
'@moderation_permissions_link' => url('admin/people/permissions/' . $rid, array(
'fragment' => 'module-workbench_moderation',
)),
)), 'warning');
// Repopulate the form with the submitted values.
$form_state['rebuild'] = TRUE;
}