You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drupal 7技术需求:隐藏Apigee自带内容类型的权限选项

如何在Drupal 7中隐藏Apigee模块未使用内容类型的权限项

要解决权限管理页面被Apigee自带的未使用内容类型权限项占满的问题,我们可以利用Drupal的钩子系统来修改权限列表,具体操作如下:

步骤1:准备自定义模块

首先,你需要一个自定义模块(如果已经有现成的自定义模块可以直接复用)。如果没有,创建一个简单的自定义模块很容易:

  • 在sites/all/modules/custom/目录下新建一个文件夹,比如hide_unused_perms
  • 新建hide_unused_perms.info文件,内容如下:
name = Hide Unused Content Type Permissions
description = Hides permissions for unused Apigee content types
core = 7.x

步骤2:实现hook_permission_alter()

在自定义模块的.module文件(比如hide_unused_perms.module)中添加以下代码:

/**
 * Implements hook_permission_alter().
 */
function hide_unused_perms_permission_alter(&$permissions) {
  // 列出所有不再使用的内容类型机器名
  $unused_content_types = ['article', 'page', 'image', 'video', 'audio'];
  
  foreach ($unused_content_types as $type) {
    // 构建该内容类型对应的所有权限条目
    $perms_to_remove = [
      "create $type content",
      "edit own $type content",
      "edit any $type content",
      "delete own $type content",
      "delete any $type content",
    ];
    
    // 从权限数组中移除这些条目
    foreach ($perms_to_remove as $perm) {
      if (isset($permissions[$perm])) {
        unset($permissions[$perm]);
      }
    }
  }
}

步骤3:启用模块并清除缓存

  1. 进入Drupal后台的模块管理页面(admin/modules),找到你创建的Hide Unused Content Type Permissions模块并启用它
  2. 清除Drupal缓存(可以通过admin/config/development/performance页面点击“Clear all caches”,或者用Drush命令drush cc all)

注意事项

  • 永远不要直接修改Apigee模块的核心代码,否则模块更新后你的修改会被覆盖,自定义模块是Drupal中做这类定制的标准做法
  • 确保$unused_content_types数组里的内容类型机器名和系统中的一致,如果Apigee的内容类型机器名有差异(比如video可能是apigee_video),需要对应调整
  • 如果之后需要恢复某个内容类型的权限,只需要从数组中移除对应的机器名,再清除缓存即可

内容的提问来源于stack exchange,提问作者Aarthi senevasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:48:35