function og_ui_user_admin_permissions in Organic groups 7
Menu callback: administer permissions.
See also
og_ui_user_admin_permissions_submit()
theme_group_ui_user_admin_permissions()
2 string references to 'og_ui_user_admin_permissions'
- og_ui_forms in og_ui/
og_ui.module - Implement hook_forms().
- og_ui_menu in og_ui/
og_ui.module - Implements hook_menu().
File
- og_ui/
og_ui.admin.inc, line 498 - Admin settings for Organic groups module.
Code
function og_ui_user_admin_permissions($form, $form_state, $entity_type = NULL, $etid = NULL, $rid = NULL) {
// If no node entity is provided then the node ID is 0, which means this
// is the default permissions settings.
$group = !empty($etid) ? og_get_group($entity_type, $etid) : array();
$form['group'] = array(
'#type' => 'value',
'#value' => $group,
);
if (!empty($group)) {
$gid = $group->gid;
og_set_breadcrumb($entity_type, $etid, array(
l(t('Group'), "{$entity_type}/{$etid}/group"),
));
}
else {
$gid = 0;
}
// Retrieve role names for columns.
$role_names = og_roles($gid);
if (!empty($rid)) {
$role_names = array(
$rid => $role_names[$rid],
);
}
// Fetch permissions for all roles or the one selected role.
$role_permissions = og_role_permissions($role_names);
// Store $role_names for use when saving the data.
$form['role_names'] = array(
'#type' => 'value',
'#value' => $role_names,
);
// Render role/permission overview:
$options = array();
$module_info = system_get_info('module');
$module = '';
foreach (og_get_permissions() as $perm => $perm_item) {
if ($perm_item['module'] != $module) {
$module = $perm_item['module'];
$form['permission'][] = array(
'#markup' => $module_info[$module]['name'],
'#id' => $module,
);
}
// Initialize values.
$perm_item += array(
'description' => '',
);
$options[$perm] = '';
$form['permission'][$perm] = array(
'#type' => 'item',
'#markup' => $perm_item['title'],
'#description' => $perm_item['description'],
);
// TODO: Move this to theme function.
// @see theme_user_admin_permissions().
if (!empty($perm_item['restrict access'])) {
$form['permission'][$perm]['#description'] .= '</br>';
$form['permission'][$perm]['#description'] .= '<em class="permission-warning">' . t('Warning: Give to trusted roles only; this permission has security implications.') . '</em>';
}
foreach ($role_names as $rid => $name) {
// Builds arrays for checked boxes for each role
if (isset($role_permissions[$rid][$perm])) {
$status[$rid][] = $perm;
}
}
}
// Have to build checkboxes here after checkbox arrays are built.
foreach ($role_names as $rid => $name) {
$form['checkboxes'][$rid] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
);
$form['role_names'][$rid] = array(
'#markup' => $name,
'#tree' => TRUE,
);
}
if (empty($group)) {
$form['#theme'] = array(
'og_ui_user_admin_permissions',
);
}
if ($gid == 0 || !og_is_group_default_access($group->gid)) {
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $gid == 0 ? t('Save global permissions') : t('Save permissions'),
'#submit' => array(
'og_ui_user_admin_permissions_submit',
),
);
}
$form['#after_build'][] = 'og_ui_user_admin_permissions_after_build';
return $form;
}