Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By sami_k on
What or where are the rules which refine whether I can call a function in another module or call it via module_invoke? Also does module_invoke allow variable references to be passed to the invoke module, which is to say changed in the module invoking the other module?
Comments
not a big difference
I'm new and was just looking at the core to answer this question myself. The answer is probably coming too late to help you but I may as well post it for anyone else who's curious.
Module_invoke doesn't do much more than call the function but it does impose Drupal's "_hook" naming convention and it checks that the function exists before calling it.
Module_invoke wants the first argument to be the module name, the second the hook, and then whatever arguments the function takes. For example:
Returns something like:
There are currently 1 user and 0 guests online.
Online users
* admin
It's asking the user module to display its block #3. Same results from: $block= user_block('view',3);
I pasted in the relevant core code for the module_invoke function below. (from module.inc, v4.7 RC1)
For people unfamiliar with all the PHP used below:- func_get_args: crams whatever arguments were passed to the function into an array
- array_shift: returns the first item of the array and removes it from the original array
- call_user_func_array: calls the function, using an array to hold the arguments
That was a usefull
That was a usefull clarification, thanks.
Displaying blocks only in frontpage