By keff on
I am building a review module that adds different info to a node displayed in full view (form + reviews) and to a node displayed in pages with several teasers (widget with avg vote, number of reviews, etc...).
How can I distinguish those two ocassions in hook_nodeapi? The only sign there is when $op=='alter', $node contains just teaser, or just body, but that seems like a bad practice to me.
Comments.module which has similar functionality does that through hook_link, but I need widget/form+review list, not just one internal link... I could set a boolean there, and act upon it in theming functions, but I think themes should should never contain forms.
Can you please help me? Thanks!
Comments
Please try hook_view instead
I think hook_nodeapi is invoked after the node or teaser list is rendered, ready in html and you should use this hook if you want to do filtering or text substitution of the html.
Please take a look at hook_view http://api.drupal.org/api/function/hook_view/5 that gives you a hook for you to add elements while the view (teaser list or node) elements are being assembled. It tells you if it is teaser or node view.
I hope this helps.
- Rajeev Karajgikar, Drupaler in South Bay Area
----------------------------------------------------------
- R Karajgikar
Thanks for a tip, but this
Thanks for a tip, but this would only work if my module created its own node type - but I want to attach reviews to any node type, and in that case, mymodule_view() doesn't get called (because type of node is not 'mymodule').
node_invoke_nodeapi $op = 'view'
node_build_contentallows modules to make their own additions to the nodes before building them. With $op = 'view', the $teaser parameter indicates whether to display the teaser only, as on the main page.Maybe this work for you, subscribing your module to
nodeapi($node, 'view', ...)?I already tried hook_nodeapi
I already tried hook_nodeapi with 'view', but in my case, I get strange results ( _tkdump($what) = var_export($what,true) ):
on summary page ( localhost/mysite ), 'view' gets called once with $a3 == 1, $a4 == false
on node page ( localhost/mysite/content/my-testing-story ), 'view' gets called two times (?!?) with
first time: $a3 == true, $a4 == false
second time: $a3 == false, $a4 == true
Any idea? Thank you for your time...
Using hook_nodeapi, case $op 'view', $teaser is true
I guess hook_view is called only for your own content type.
I think, if you use hook_nodeapi and code for the case $op == 'view', then the php global $teaser is true if it is a teaser being shown. If you read the code of hook_view ( http://api.drupal.org/api/function/node_view/6 ) that invokes all hook_nodeapi, it uses $teaser to render what is to be shown.
I guess you can use if ($teaser) {} construct to figure out if you are currently showing teaser list or full node page.
I hope this helps. Thanks
- Rajeev Karajgikar, Drupaler in South Bay Area
----------------------------------------------------------
- R Karajgikar
Did you succeed?
Hi,
I'm facing the same question : how to distinguish teaser from full page in hook_nodeapi.
Did you succeed?
cfab
[Edit] solved for me :
I was using this signature :
function contact_link_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {}instead of :
function contact_link_nodeapi(&$node, $op, $teaser, $page) {}I didn't understand hook_nodeapi documentation.
[/Edit]
Drupal rocks!
www.tahiticlic.com
node_invoke_nodeapi $op = 'view'
node_build_contentallows modules to make their own additions to the nodes before building them. With $op = 'view', the $teaser parameter indicates whether to display the teaser only, as on the main page.Maybe this work for you, subscribing your module to
nodeapi($node, 'view', ...)?