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
Hi I added the 2 additional settings in settings.php, did a restart - and the error disappeared! Thanks for the support! (but the issues with the conversion still remain .....
Problem with utf8mb4 Format when importing database
With JQuery, simple and fast. Or put all possible links in one menu, and hide unnecessary with CSS mediaquery.
Different primary menus depending on the viewport size?
I wonder if what is happening here is the default database settings are for utf8mb4 if the database server supports it. In settings.php or settings.local.php if that's where you put your...
Problem with utf8mb4 Format when importing database