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
Tried and successfully applied DrAlbany's method with the form https://www.drupal.org/sandbox/grobot/2105379stickman hook. I also encountered the same situation. Thanks DrAlbany
Ubercart - Auto increment SKU
Since before migration you need to prepare the Drupal site - disabling and removing all modules, disabling themes, as part of the preparation you can clear the cache and logs, delete the search...
Trimming the size of my database for D2B_migrate not to error out (Request Entity Too Large / 504 Gateway Time-out)
QuickTabs is now available!!! But does not work as expected, already reported (https://github.com/backdrop-contrib/quicktabs/issues/14). Maybe an alternative solution using Views...
Quick Tabs (or method to simulate)