Drupal 7以编程方式从不同模块调用钩子函数

时间:2022-09-12 08:40:04

How do I call a hook function in a separate file from mymodule.module?

如何在mymodule.module的单独文件中调用钩子函数?

Using Features and Node Export, there is array data returned from a hook_node_export_features_default function. I want to retrieve that array data in the .module file of the same module but when I try calling the function directly:

使用功能和节点导出,从hook_node_export_features_default函数返回的数组数据。我想在同一模块的.module文件中检索该数组数据,但是当我尝试直接调用该函数时:

$data = mymodule_node_export_features_default();
dsm($data, 'Import Data');

I get the following error

我收到以下错误

Fatal error: Call to undefined function

致命错误:调用未定义的函数

How can I call such a function successfully?

我怎样才能成功调用这样的函数?

1 个解决方案

#1


module_invoke_all(); 

should do the trick to call hooks : https://api.drupal.org/api/drupal/includes!module.inc/function/module_invoke_all/7

应该做的事就是调用钩子:https://api.drupal.org/api/drupal/includes!module.inc/function/module_invoke_all/7

if you to call a particular function, you'll need to include the module file that contains this function.

如果要调用特定函数,则需要包含包含此函数的模块文件。

module_load_include('module', 'mymodule'); $data = mymodule_node_export_features_default(); 
dsm($data, 'Import Data');

#1


module_invoke_all(); 

should do the trick to call hooks : https://api.drupal.org/api/drupal/includes!module.inc/function/module_invoke_all/7

应该做的事就是调用钩子:https://api.drupal.org/api/drupal/includes!module.inc/function/module_invoke_all/7

if you to call a particular function, you'll need to include the module file that contains this function.

如果要调用特定函数,则需要包含包含此函数的模块文件。

module_load_include('module', 'mymodule'); $data = mymodule_node_export_features_default(); 
dsm($data, 'Import Data');