Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 同一模块定义的多个内容类型的hook_表单_Drupal - Fatal编程技术网

Drupal 同一模块定义的多个内容类型的hook_表单

Drupal 同一模块定义的多个内容类型的hook_表单,drupal,Drupal,一个新模块“foo”实现了一个或多个新内容类型的定义 如果定义了两种内容类型,即内容类型“footypea”和内容类型“footypeb”,如何实现(hook的名称应该是什么?)来配置每个节点的编辑表单 在中,新内容类型的名称与模块名称相同。在上述示例中,模块定义了两种新的内容类型,会发生什么情况 实现的hook_form()函数的形式应该是:footypea_form()和footypeb_form()?(这似乎不起作用) 还是应该实现一个foo_form()函数,并在此函数中创建并返回一个数

一个新模块“foo”实现了一个或多个新内容类型的定义

如果定义了两种内容类型,即内容类型“footypea”和内容类型“footypeb”,如何实现(hook的名称应该是什么?)来配置每个节点的编辑表单

在中,新内容类型的名称与模块名称相同。在上述示例中,模块定义了两种新的内容类型,会发生什么情况

实现的hook_form()函数的形式应该是:footypea_form()和footypeb_form()?(这似乎不起作用)


还是应该实现一个foo_form()函数,并在此函数中创建并返回一个数组$form,其中的元素$form['footypea']和$form['footypeb'],这两个元素依次是各个表单字段定义的数组?

在Drupal中实现挂钩时,调用什么节点类型无关紧要,第一部分是创建它们的模块的名称。在这里,您的foo模块在foo_form()中实现hook_form()


顺便说一句,因为它更简单,而且是Drupal 7中提供的,所以您还应该查看CCK以创建内容类型。

在模块的hook_node_info()中,添加
'module'
属性(请参阅)

例如:

/**
 * Implementation of hook_node_info().
 */
function foo_node_info() {
  return array(
    'footypea' => array(
      'name' => t('Foo Type A'),
      'description' => t('This is Foo Type A'),
      'module' => 'footypea',  //This will be used for hook_form()
    ),
    'footypeb' => array(
      'name' => t('Foo Type B'),
      'description' => t('This is Foo Type B'),
      'module' => 'footypeb',  //This will be used for hook_form()
    ),
  );
}
现在可以为每种类型添加以下hook_form()实现(请参阅)


这里的技巧是
hook\u node\u info()
中每个元素的模块属性不必与实现
hook\u node\u info()
的模块相同。定义的每个类型都可以有一个唯一的模块属性来实现特定于类型的钩子。

+1:是的,这绝对正确,对于其他特定于内容类型的钩子也是如此:例如
footypea\u访问($op,$node,$account)
footypea\u访问($op,$node,$account)
footypea\u验证($node,&$form)
footypeb\u验证($node,&$form)
footypeb\u插入($node)
footypeb\u插入($node)
footypeb\u更新($node)
footypeb\u删除($node)
footypeb\u删除($node)
,等等。
/**
 * Implementation of hook_form().
 */
function footypea_form(&$node, $form_state) {
  // Define the form for Foo Type A
}

/**
 * Implementation of hook_form().
 */
function footypeb_form(&$node, $form_state) {
  // Define the form for Foo Type B
}