在Drupal教程中添加新的自定义权限

Jig*_*tak 1 php drupal drupal-7 drupal-modules

我现在创建模块我想在该模块上设置权限,以便一些用户可以看到该字段.我搜索谷歌和stackoverflow但我没有得到正确的答案,因为我需要.我的代码如下

function downloaded_menu() {
     $items['user/%user/downloaded_poems'] = array(
    'title' => 'Downloaded Poems',
    'page callback' => 'downloaded_content_page',
    'access arguments' => array('poet downloaded work'),    
    'type' => MENU_LOCAL_TASK,
    'weight' => 11,
  );
  return $items;
}
Run Code Online (Sandbox Code Playgroud)

现在我想给予特定用户许可.谁只能看到.

Muh*_*eda 5

您将不得不使用hook_permission来执行此操作.

代码示例:

function downloaded_permission()
{
    return array(
        'poet downloaded work' => array(
            'title' => t('poet downloaded work'), // the title to be shown in the permissions page
            'description' => t('poet downloaded work'), // the description to be shown in the permissions page
            'restrict access' => FALSE,
        ),
    );
}
Run Code Online (Sandbox Code Playgroud)

然后转到权限页面并授予所需角色的权限.

希望这有助于......穆罕默德.