Modules can specify permissions via hook_permission()
:
function my_awesome_module_permission() {
return array(
'permission x' => array(
'title' => t('Permission to do x'),
'description' => t('Allows people to do x.'),
'restrict access' => TRUE,
'warning' => t('Allows people to do ...'),
),
'permission y' => array(
'title' => t('Permission to do y'),
'description' => t('Allows people to do y.'),
),
);
}
Now, we have user_access()
, which allows us to determine if a user has a specific permission:
$user_can_do_x => user_access('permission x');
$user_can_do_y => user_access('permission y');
...and we also have user_permission_get_modules()
, which returns all permissions, along with which module implements each permission.
...but we don't have any function that returns the properties of a permission. So each time we need to reference a permission say in some help text, we do this:
$form['whatever'] = array(
...
'#description' => t('This option depends on the "Permission to do y" permission.',
...
);
This is OK, but if at some point we rename the permission (change it's 'title'
), then we need to do a search and replace (at best), in order to find all instances of the literal permission title in the codebase, and update it to the new name/label. Ideally though, we should be able to do something like this:
$permission_info = user_permission_get_info('permission x');
$form['whatever'] = array(
...
'#description' => t('This option depends on the @permission permission.', array('@permission' => $permission_info['title'],
...
);
That way, we would only need to update any permission info in a single place (in its hook_permission()
function), which also makes translators' life easier.
As a developer, at minimum I would like this new function to return:
- the title of the permission
- the description of the permission
...additional nice-to-have's:
- an admin path, which can be used to provide a link to
/admin/config/people/permissions#permission x
(scrolls the permissions listing page to the specific permission) - the module that specifies the hook of the permission (alternatively, have
user_permission_get_modules()
accept an optional$permission
parameter, so to be able to douser_permission_get_modules('permission x')
). This could also be used as a search/filter query when #980 gets implemented - a list of all user roles this permission has been assigned to (we have
user_roles()
for that - still nice to have)
Recent comments
Hello @NumerousHats, I agree with your assessment. I am looking into this situation right now. The root of this problem is that Backdrop CMS is implemented on top of a "stack" of...
Update Core and Theme via Web interface
I just installed a Backdrop CMS site with version 1.27.0. I then used the user interface to download and update Backdrop CMS to 1.30.0. After starting the update process, and on the...
1.30.0 update.php generates incorrect link
I believe my permissions are set up correctly, as I can install modules from the UI. But for whatever reason, I can't update them. I will, however, double check against that documentation.
Update Core and Theme via Web interface