Strapi 隐藏内容类型

Strapi Hide Content Type

我搜索了几个小时如何隐藏特定内容类型。

我找到了一些 post 但它们太老了,它们的解决方案在实际的 strapi 中不起作用。

为了精确起见,我的 collection 类型是在本地插件中声明的。我只是想在插件页面中管理我的 collection,我不希望它出现在左侧菜单的内容类型中。

如果有人有解决方案,那将非常有帮助。

他们正在研究这个:https://github.com/strapi/rfcs/pull/22

但目前,根据官方文档 (plugin customization),您可以在内容管理器插件中覆盖文件。

确保在 strapi 更新时检查此文件以避免覆盖重要代码。

  1. 将文件 strapi-plugin-content-manager/services/data-mapper.js 从您的应用 node_modules 复制到 extensions/content-manager/services/

  2. 现在在您的项目中编辑此文件并将您的内容类型添加到数组 HIDDEN_CONTENT_TYPES 中,遵循以下模式:plugins::[plugin-name].[content-type] 例如:plugins::ecommerce.product

...

const HIDDEN_CONTENT_TYPES = [
  'plugins::upload.file',
  'plugins::users-permissions.permission',
  'plugins::users-permissions.role',
  'plugins::ecommerce.product',
];

...

新版本的 Strapi v3.6.6 — Community Edition 模型中有一个选项

{
  "kind": "collectionType",
  "collectionName": "test",
  "info": {
    "name": "test"
  },

  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": true
  },

  **"pluginOptions": {
    "content-manager": {
      "visible": false
    }
  },**

  "attributes": {
    "name": {
      "type": "string",
      "required": true
    },
    
  }

}

您可以扩展插件以更新 content-type 的架构。

将 content-type 架构从插件复制到您的 src 文件夹。

在我的例子中,我将 /strapi-plugin-navigation/server/content-types/audience/schema.json 复制到 /src/extensions/navigation/content-types/audience/schema.json(注意文件夹名称的 strapi-plugin- 部分已被删除)并向其中添加以下内容以隐藏“Audience " 来自内容管理器和 content-type 构建器的内容类型:

"pluginOptions": {
   "content-manager": {
     "visible": false
   },
   "content-type-builder": {
     "visible": false
   }
},

官方文档here.

在 Strapi v4 中是 "visible": false

{
  "kind": "collectionType",
  "collectionName": "bookmark",
  "info": {
    "singularName": "bookmark",
    "pluralName": "bookmarks",
    "displayName": "Bookmark",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "index": {
      "type": "integer",
      "unique": false,
      "visible": false
    },
  }
}