I'm a newcomer trying to follow along in Pro Drupal Development 2nd edition's examples.
In a sample module on page 20, under the code for hook_nodeapi(), is the following:
if (!in_array($node->type, $types_to_annotate))
{break;}
$types_to_annotate is just an array populated with node types for which the module has been enabled. So basically, this line just says not to use this module with this node, unless the user has told it to in the settings menu.
That's fine, except that Drupal seems to be ignoring this piece of code. If I enable the module, its functionality shows up with all of my node types, regardless of what checkboxes I have set in the settings menu.
I verified that $types_to_annotate is in fact being populated with the correct values from the setting menus, by simply putting a print_r in the hook_nodeapi code. Everything looks OK:
Array ( [book] => book [page] => 0 [story] => 0 )
So I have a situation where the Annotation module is enabled and I have selected it to work ONLY with the "book page" node type, and then I navigate to, say, a Story node, and there's the Annotation functionality anyway. Note that I also have a print_r statement showing up on the top all my node pages, so I can see the print_r output shown above.
Any ideas what I'm doing wrong?
Thanks!
Comments
Without the full function it
Without the full function it would be a wild guess, first thought is you have a typo, but's it only a guess. You might want to post the function. (remember to place between <code> and </code> tags).
/*** Implementation of
It's this part that seems to be at the core of everything:
It seems the in_array function is finding $node->type in $types_to_annotate even if $node->type simply isn't there. (Well, it is there as a key, but not a value. It's my understanding that this function only finds values?) Here's the output of print_r on $types_to_annotate:
Array ( [book] => book [page] => 0 [story] => 0 )
So obviously, when I'm looking at, say, a Story, $node->type should be "story" (and it is) and should *not* be found -- but it is.
Here's a thing that baffles me: if I replace this:
with this:
I get the same result. So it seems like in_array thinks it's finding "nonsense" in $types_to_annotate. But the print_r of $types_to_annotate (shown above) shows that that word isn't in there at all
So that led me to believe that in_array was somehow not working, and whatever I searched for, it would think it found it. But no, because if I replace the line with this:
it does not find $node (as opposed to node->type) in $types_to_annotate.
At this point I hope I'm being really stupid, because that would lead to an easier answer. Thanks for looking at this!
Did you ever solve this? I'm
Did you ever solve this? I'm having the same problem.
I made it work by adding the
I made it work by adding the check for type, like this:
I've updated this in the
I've updated this in the downloadable code.
I've the same problem whit $types_to_annotate
and i found the solution in Errata for (Second Edition) "Pro Drupal Development" book
http://www.drupalbook.com/node/186
if (!in_array($node->type, $types_to_annotate, TRUE))
Great book bay the way!
Ratio Web