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, @yorkshirepudding! Thanks a lot, I got it, all sorted out.
My layout template (layout--blog.tpl.php) doesn't work
Hi @Gnome and welcome to Backdrop When I create custom layout templates I put them in /layouts/custom/my_layout Note: you can split modules and layouts between contrib and custom...
My layout template (layout--blog.tpl.php) doesn't work
This post explains how to do this in Drupal 7. In Backdrop, File Entity is already part of core. You will need to download and install module Views Field View. https://drupal.stackexchange...
I Need to Display an Image in a View that was Uploaded to a Webform