Question

I am using the node_clone module with great effect but there is a need in my project to use node_clone functions from my custom module. So I put in the following code:

module_load_include('inc', 'node_clone', 'clone.pages');

function mymodule_init(){
    clone_node_save(118);
}

That code returns Fatal error: Call to undefined function clone_node_save().

My modules are categorized by source into directories labelled mine and contrib. Node_save is in contrib while myModule is in mine.

So, I amended the code acordingly as follows:

module_load_include('inc', '../../contrib/node_clone', 'clone.pages');

but I get the same error.

Can anyone highlight what I'm doing wrong, please?

Was it helpful?

Solution 2

It's a bit misleading, the folder is named 'node_clone' but the module is actually called 'clone', so you want:

module_load_include('inc', 'clone', 'clone.pages');

hook_init() runs pretty early on so if you don't need the clone module's functions before hand, you'd be better off moving the code into the hook:

function mymodule_init(){
  module_load_include('inc', 'clone', 'clone.pages');
  clone_node_save(118);
}

OTHER TIPS

Use:

require_once DRUPAL_ROOT . '/sites/all/modules/contrib/node_clone/clone.pages.inc';

From the module_load_include API:

Do not use this function in a global context since it requires Drupal to be fully bootstrapped, use require_once DRUPAL_ROOT . '/path/file' instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top