5 * Plugin to provide access control based on user permission strings.
9 * Plugins are described by creating a $plugin array which will be used
10 * by the system that includes this file.
13 'title' => t("User: permission"),
14 'description' => t('Control access by permission string.'),
15 'callback' => 'ctools_perm_ctools_access_check',
16 'default' => array('perm' => 'access content'),
17 'settings form' => 'ctools_perm_ctools_access_settings',
18 'summary' => 'ctools_perm_ctools_access_summary',
19 'required context' => new ctools_context_required(t('User'), 'user'),
23 * Settings form for the 'by perm' access plugin
25 function ctools_perm_ctools_access_settings($form, &$form_state, $conf) {
27 // Get list of permissions
28 foreach (module_list(FALSE, FALSE, TRUE) as $module) {
29 // By keeping them keyed by module we can use optgroups with the
31 if ($permissions = module_invoke($module, 'permission')) {
32 foreach ($permissions as $id => $permission) {
33 $perms[$module][$id] = $permission['title'];
38 $form['settings']['perm'] = array(
41 '#title' => t('Permission'),
42 '#default_value' => $conf['perm'],
43 '#description' => t('Only users with the selected permission flag will be able to access this.'),
52 function ctools_perm_ctools_access_check($conf, $context) {
53 // As far as I know there should always be a context at this point, but this
55 if (empty($context) || empty($context->data)) {
59 return user_access($conf['perm'], $context->data);
63 * Provide a summary description based upon the checked roles.
65 function ctools_perm_ctools_access_summary($conf, $context) {
66 if (!isset($conf['perm'])) {
67 return t('Error, unset permission');
70 $permissions = module_invoke_all('permission');
71 return t('@identifier has "@perm"', array('@identifier' => $context->identifier, '@perm' => $permissions[$conf['perm']]['title']));