简体   繁体   English

如何在 Drupal 8 中使用 Drush 命令创建新的内容类型

[英]How to create new content types using Drush commands in Drupal 8

I know the export and import option is available but I have 5 environments, So each and every time after implementing new things on dev env I don't want to do export and import on other envs instead using pipeline I will execute the drush commands to implement the required changes on other envs by executing required Drush commands.我知道导出和导入选项可用,但我有 5 个环境,所以每次在开发环境上实现新事物后,我不想在其他环境上进行导出和导入,而是使用管道我将执行 drush 命令通过执行所需的 Drush 命令在其他环境上实现所需的更改。

The problem is that on Drupal the config import/export is the best way to do that.问题是在 Drupal 上,配置导入/导出是最好的方法。 The config export doesn't not only export content type configuration, but the entire website configuration.配置导出不仅导出内容类型配置,还导出整个网站配置。

So thoses commands help you be iso between environments.因此,这些命令可以帮助您在环境之间保持独立。

If your probleme is about ouverriding some config values between environments, the module Config Split can help you on it.如果您的问题是关于在环境之间覆盖某些配置值,模块Config Split可以帮助您。

With no config import, I would solve it with installing a module of your own, which runs your special code .如果没有配置导入,我会通过安装您自己的模块来解决它,该模块运行您的特殊代码

Steps:脚步:

  • Create a module my_custom_contenttype创建一个模块 my_custom_contenttype
  • Make a hook_install() (my_custom_contenttype_install())制作一个hook_install() (my_custom_contenttype_install())
  • Run this drush command (uninstall before, if you want to install it again - do it more than one time):运行这个drush 命令(之前卸载,如果你想重新安装 - 执行多次):
drush pm:uninstall my_custom_contenttype; drush pm:enable my_custom_contenttype;
function my_custom_contenttype_install(){
// Add content type if it not exist
};

You could do this using manually-managed configuration.您可以使用手动管理的配置来执行此操作。 Either by:或者通过:

  1. Creating a custom module and including your configurations in custom_module/config/install, and using "drush en" to install the module OR创建自定义模块并将您的配置包含在 custom_module/config/install 中,并使用“drush en”安装模块或
  2. By using an existing custom module and using a post_update hook to install the configuration.通过使用现有的自定义模块并使用 post_update 挂钩来安装配置。

We do this on a number of sites, and loading and installing the configurations is just complex enough that we built a helper module to do it.我们在许多站点上都这样做,加载和安装配置非常复杂,我们构建了一个辅助模块来完成它。 You can pull this module in with composer and use update hooks to activate it, or you can look at the installConfig function here and use it a as a template.您可以使用 composer 拉入此模块并使用更新挂钩来激活它,或者您可以查看此处的 installConfig function 并将其用作模板。 (the module has a helpful readme, too). (该模块也有一个有用的自述文件)。

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

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