Valid access arguments

耗尽温柔 提交于 2019-12-06 13:18:56

Invoke hook_permission() across all modules:

$permissions = module_invoke_all('permission');

If I remember rightly array_keys($permissions) will then give you a list of valid permission machine names. The labels/descriptions/other settings for each permissions are in each individual array item.

Actually, you are interested to the values of the access arguments where the access callback is "user_access" (the default value); as a module can use a different access callback, the values for the access arguments can theoretically be infinite.

The alternative to invoking all the implementations of hook_permission() is to use code similar to the following one:

$permissions = array();
db_query("SELECT permission FROM {role_permission}");

foreach ($result as $row) {
  $permissions[$row->permission] = TRUE;
}

array_keys($permissions) will then give you the list of all the permissions.

I took the query from user_role_permissions(); the difference is that the function is interested in the permissions associated to the role passed as argument.

1- Check a list of valid permissions at: /admin/people/permissions

2- Specify the permission in your menu hook:

function webforms_advanced_router_menu() {

  $items['admin/config/mymodule'] = [
    'title' => 'MyModule',
    'page callback' => 'drupal_get_form',
    'access callback' => '_mymodule_admin_form',
    'access arguments' => array('administer site configuration'),
    'type' => MENU_CALLBACK
  ];

  return $items;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!