Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I tried using module_invoke('casrel','nodeapi', $node, 'view'), but what I get for casrel_nodeapi() is a truncated $node and "load" instead of "view".

Does anybody have an idea on what is happening?

share|improve this question

2 Answers

You are probably looking for module_invoke_all. The module_invoke function only invokes a module in a specific module (casrel.module in your example).

By the way, you usually do not need to invoke hook_nodeapi yourself. The node module invokes hook_nodeapi when necessary, if you just use the api functions (like node_view) correctly. If you need to alter a node before it's viewed, you need to implement hook_nodeapi instead of invoking it.

share|improve this answer
marcvangend, thank you for your comment – Víctor Nov 8 '11 at 9:38
marcvangend, thank you for your comment - I'm making a batch to visit all nodes of certain type trying to apply casrel_nodeapi - it doesn't work because $op should be 'view' and it becomes 'load' and $node reaches truncated – Víctor Nov 8 '11 at 9:44
So can't you just call node_view() or node_build_content() on all nodes of that type? – marcvangend Nov 8 '11 at 9:53
It seems the OP is interested in invoking the hook for just a module. While I agree about not invoking hook_nodeapi() directly, this answer doesn't explain why invoking hook_nodeapi('view') has the result of invoking `hook_nodeapi('load'). I get something is wrong with the code the OP is using. – kiamlaluno Nov 8 '11 at 13:57
Kiam, maybe you are right, I may have misunderstood the intentions of the OP. – marcvangend Nov 8 '11 at 14:13
show 1 more comment

Does module_invoke() work for non core modules?

Yes, it does. For module_invoke() there isn't a difference between core modules, and third-party modules as the function doesn't verify the module being called is contained in a particular list, and Drupal doesn't have a way to know if a module is a Drupal core one, or not. There are many third-party modules that use module_invoke(), and none of them has issues with the function (if it is called with the right parameters).

I agree with marcvangend that you are invoking hook_nodeapi() directly when you should be using a function that Drupal make available. Still, if you are having issues with module_invoke(), then there is something wrong with your code, or you are not tracing correctly all the calls to the implementation of hook_nodeapi() for that module.
For example, when a module implements hook_nodeapi(), that hook is called from Drupal code. Are you sure that casrel_nodeapi('load') is being called from Drupal core, and it is not what module_invoke('casrel','nodeapi', $node, 'view') is causing? Consider that Drupal always invoke hook_nodeapi('load') before hook_nodeapi('view') because a node is first loaded, and then shown.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.