| Versionen | |
|---|---|
| drupal6 – drupal7 | user_admin_perm($form_state, $rid = NULL) |
Menu callback: administer permissions.
modules/
<?php
function user_admin_perm($form_state, $rid = NULL) {
// Retrieve role names for columns.
$role_names = user_roles();
if (is_numeric($rid)) {
$role_names = array($rid => $role_names[$rid]);
}
// Fetch permissions for all roles or the one selected role.
$role_permissions = user_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();
$hide_descriptions = !system_admin_compact_mode();
foreach (module_implements('perm') as $module) {
if ($permissions = module_invoke($module, 'perm')) {
$info = drupal_parse_info_file(drupal_get_path('module', $module) . "/$module.info");
$form['permission'][] = array(
'#markup' => $info['name'],
'#id' => $module,
);
foreach ($permissions as $perm => $perm_item) {
$options[$perm] = '';
$form['permission'][$perm] = array(
'#type' => 'item',
'#markup' => $perm_item['title'],
'#description' => $hide_descriptions ? $perm_item['description'] : NULL,
);
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);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
$form['#attached_js'] = array(drupal_get_path('module', 'user') . '/user.permissions.js');
return $form;
}
?>
Kommentare
Kommentar hinzufügen