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 Steve, you can add a site-wide language switcher for visitors as a block to your layout(s). To do so, go to your layout, click "Add block", e.g. in the Header region, search for "language",...
How to translate my site content
As some folks have mentioned, some work has gone into this. We actually added the ability to have "draft revisions" into core, BUT we never completed the front end user interface for this...
managing draft revisions while still having a version published
Hi danryan, just to be sure, can you check if the tabs aren't hidden in your layout? Go to the page where you miss the tabs. In the Admin bar at top of the page...
View/Edit tabs missing