简体   繁体   English

Strapi 隐藏内容类型

[英]Strapi Hide Content Type

I've search for several hours how to hide a specific content type.我已经搜索了几个小时如何隐藏特定的内容类型。

I found some post but they are too older and their solutions doesn't work in the actual's strapi.我找到了一些帖子,但它们太旧了,而且它们的解决方案在实际的 strpi 中不起作用。

For precisions, my collection type is declared inside a local plugin.为了精确起见,我的集合类型是在本地插件中声明的。 I juste want to manage my collection inside the plugin page and I doesn't want it appear in the content type in the left menu.我只是想在插件页面中管理我的收藏,我不希望它出现在左侧菜单的内容类型中。

If someone has a solution, it's can be really helpfull.如果有人有解决方案,那真的很有帮助。

In new version of Strapi v3.6.6 — Community Edition there is an option in model在新版本的 Strapi v3.6.6 — 社区版中,model 中有一个选项

{
  "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
    },
    
  }

}

They are working on this: https://github.com/strapi/rfcs/pull/22他们正在研究这个: https://github.com/strapi/rfcs/pull/22

But for now, based on official docs ( plugin customization ), you can overwrite file in content-manager plugin.但目前,基于官方文档( 插件定制),您可以覆盖内容管理器插件中的文件。

Be sure to check this file on strapi updates to avoid overwriting important code.请务必检查有关 Strapi 更新的此文件,以避免覆盖重要代码。

  1. Copy file strapi-plugin-content-manager/services/data-mapper.js from your app node_modules into extensions/content-manager/services/将文件strapi-plugin-content-manager/services/data-mapper.js从您的应用程序 node_modules 复制到extensions/content-manager/services/

  2. Now edit this file in your project and add your content type to array HIDDEN_CONTENT_TYPES following this pattern: plugins::[plugin-name].[content-type] For example: plugins::ecommerce.product现在在您的项目中编辑此文件,并按照以下模式将您的内容类型添加到数组HIDDEN_CONTENT_TYPESplugins::[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',
];

...

You can extend the plugin to make updates to the content-type's schema.您可以扩展插件以更新内容类型的架构。

Copy the content-type schema from the plugin to your src folder.将内容类型架构从插件复制到您的 src 文件夹。

In my case, I copied /strapi-plugin-navigation/server/content-types/audience/schema.json to /src/extensions/navigation/content-types/audience/schema.json (notice that the strapi-plugin- part of the folder name is removed) and added the following to it to hide the "Audience" content type from the content manager and content-type builder:就我而言,我将/strapi-plugin-navigation/server/content-types/audience/schema.json复制到/src/extensions/navigation/content-types/audience/schema.json (请注意, strapi-plugin-部分文件夹名称的名称被删除)并添加以下内容以从内容管理器和内容类型构建器中隐藏“受众”内容类型:

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

Official documentation here .官方文档在这里

In Strapi v4 it is "visible": false在 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
    },
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM