drupal - 如何在 Drupal 7 中以编程方式创建新的内容类型?

标签 drupal module drupal-7 content-type

我正在 Drupal 7 中构建一个模块( my_module )。

它有一些功能,也会创建新的内容类型。

在 my_module.install 中,我实现了 hook_install (my_module_install)。

我可以使用多个 hook_install 的实现吗?在这个模块中创建新的内容类型(my_cck_install)?

如果(是),我应该怎么做?

其他:我是否在另一个模块中执行此操作? :-)

最佳答案

您不能使用多个 hook_install 的实现。在同一个模块中;在 PHP 中,你不能有 2 个同名的函数来排除这种情况。

您只需在同一 hook_install 中添加新的内容类型无论如何(看看标准安装配置文件是如何在/profiles/standard/standard.install 中完成的)。这就是我总是从安装文件中添加新内容类型的方式(使用推荐模块的示例):

function testimonial_install() {
  // Make sure a testimonial content type doesn't already exist
  if (!in_array('testimonial', node_type_get_names())) {
    $type = array(
      'type' => 'testimonial',
      'name' => st('Testimonial'),
      'base' => 'node_content',
      'custom' => 1,
      'modified' => 1,
      'locked' => 0,
      'title_label' => 'Customer / Client Name'
    );

    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
  }
}

关于drupal - 如何在 Drupal 7 中以编程方式创建新的内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8118634/

相关文章:

css - Drupal Views 幻灯片标题未随浏览器调整大小

linux - 为导出设备 linux 内核构建一个 sk_buff

c++ - 关于 C++ 20 模块的困惑

mysql - 我是否应该在正在运行的 Drupal 7 站点上将非 utf-8 数据库 (mysql)(默认?)更改为 utf-8?

drupal - 使用 Drupal Views VS 模板

drupal - 如何为挂起的站点调试 nginx/php-fpm?

user-interface - 用于显示分层餐厅菜单的最佳 Drupal GUI?

node.js - 跨平台模块系统

Drupal 7 preprocess_views 不起作用

drupal-7 - 预处理对比drupal模板中的流程函数