Hello,
I have a serious problem :)
I am creating a new module mymodule.module. I have one function that seems to be a hook but it's not a real one. I have called
it :

	function mymodule_myfunction() {
		return "Thanks Drupal!";
	}

I have added mymodule. Now I have created a new "PHP code" node. I would like to invoke this function from the node so I want to write something like below in the body of the node :

	print module_invoke ('mymodule', 'myfunction');

But it doesn't work :((
I Check with function_exists('myfunction'), it's not found!

How to explain this? and how to call this function?
Regards.

Comments

profix898’s picture

Your function_exists('myfunction') doesnt work, because your functions
is named 'mymodule_myfunction' and not 'myfunction' only.
I think you got the same problem with your hook: module_invoke takes
the modules name (without .module) as first parameter and the function
to invoke as second parameter. So you should try:
module_invoke ('mymodule', 'mymodule_myfunction');

amino_ab’s picture

 function mymodule_myfunction() {
return "Thanks Drupal!";
}

and to invoke this function :

print module_invoke ('mymodule', 'myfunction');

but to check the existence of the function you are right :

echo function_exists('mymodule_myfunction');

Anyway, it is still not working!

the_other_mac’s picture

To invoke the function, you wrote:

print module_invoke ('mymodule', 'myfunction');

It should be:

print module_invoke ('mymodule', 'mymodule_myfunction');
amino_ab’s picture

function module_invoke() {

  $args = func_get_args();
  $module = array_shift($args);
  $hook = array_shift($args);

    $function = $module .'_'. $hook;
  if (module_hook($module, $hook)) {
    return call_user_func_array($function, $args);
  }
}

function module_hook($module, $hook) {
    return function_exists($module .'_'. $hook);
}

module_hook is returning false in my case.
why?

nevets’s picture

Have you enabled the module under admnister -> modules?

amino_ab’s picture

Yes, it's enabled and I can see all the standard hooks (_view, _form, ..) but function_exists fails with customized functions. I have trying to solve the problem by adding one include.inc file. It works of course, but I still want the clean solution.

profix898’s picture

Uuupps. Sorry! You are right with module_invoke, of course!
When function_exists returns true with your arguments, how can
module_hook return false then?