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

rkarajgi’s picture

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

keff’s picture

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').

dropcube’s picture

node_build_content allows 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.

  // Allow modules to make their own additions to the node.
  node_invoke_nodeapi($node, 'view', $teaser, $page);

Maybe this work for you, subscribing your module to nodeapi($node, 'view', ...) ?

keff’s picture

I already tried hook_nodeapi with 'view', but in my case, I get strange results ( _tkdump($what) = var_export($what,true) ):

function productreview_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
    	drupal_set_message("<h2>$op</h2>"._tkdump($a3)._tkdump($a4)."<hr />"._tkdump($node)."<hr />",'status');
    	break;
    }
}

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...

rkarajgi’s picture

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

tahiticlic’s picture

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

dropcube’s picture

node_build_content allows 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.

  // Allow modules to make their own additions to the node.
  node_invoke_nodeapi($node, 'view', $teaser, $page);

Maybe this work for you, subscribing your module to nodeapi($node, 'view', ...) ?