Closed (fixed)
Project:
Related Block
Version:
5.x-0.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
12 Nov 2007 at 17:41 UTC
Updated:
18 Mar 2008 at 16:31 UTC
Jump to comment: Most recent file
In "function related_block_block" there is a mistake when checking for the content type to see if it is in the list of types where the related block should appear.
$types = variable_get("related_block_types", node_get_types('names') );
if (array_key_exists($node->type, $types)) {
Should be something like the following as the content_types are in the value field, not in the key field.
$types = variable_get("related_block_types", node_get_types('names') );
if (in_array($node->type, $types)) {
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | related_block.191562.patch | 2.95 KB | spiderman |
Comments
Comment #1
spidermanwhoops- this bug is actually fixed by this commit to the cvs, but I neglected to post a proper issue to reflect it. I'll plan to roll up a new release for this module shortly. In the meantime, changing the one line above fixes this bug.
Comment #2
spidermanlooking at this more closely, I realized that this is not actually a duplicate, but rather the *reverse* of this bug, and is thus already fixed.
the node_get_types() call returns an array keyed by node *type*, which is the same type value stored in the $node->type object field. the array_key_exists() call is therefore appropriate, and when I switched it back to an in_array() call on my test site, the related_links block disappeared.
@nath: can you confirm that you either reported this backwards, is not really a bug, or is perhaps some eccentricity with your particular installation?
Comment #3
nath commentedIt is like I have reported.
This line:
$types = variable_get("related_block_types", node_get_types('names') );returns the following array:
As you can see, the types are in the values.
Comment #4
spidermanok this is very bizarre- when I print out the $types array by adding lines like this, just after the call to node_get_types():
I see the following:
* node_get_types(names): Array ( [page] => Page [story] => Story [weblink] => weblink ) * node->type: pageI've also checked this to see if the result is the same when there is no "related_block_types" variable set- the array looks basically the same either way. Is it possible we have a version mismatch somewhere, perhaps?
Comment #5
nath commentedHmm, weird. One thing that comes to mind: Do you have custom content types in your installation?
Comment #6
nath commentedI just noticed: The array that I get is not returned by node_get_types('names'). It is the one in "related_block_types". The node_get_types function returns the same as with you but it is only called if the "related_block_types" variable is empty.
Comment #7
spidermanah-ha! now we're onto something- I did indeed have a contrib content type 'weblink' enabled, by virtue of having installed the links package. when I disabled that module, and then added "page" and "story" to the related_block_types variable (from the /admin/build/block/configure/related_block/0 page), a node view with (a slight variation of) my previous debug code reproduced your "version" of this bug:
* types: Array ( [0] => page [1] => story ) * node_get_types(names): Array ( [page] => Page [story] => Story ) * node->type: pageit appears the real bug here is hidden in the variable_get() call's arguments, which do not return the same type of value (thus causing the if statement to fail in some cases, pass in others). so we need to normalize the arguments here, so that the testing condition will yield the correct result for all cases. i see two options:
1) fix the return value of the node_get_types() call, so that it matches the format of the array stored in the 'related_block_types' variable
2) fix the 'save' subhook in hook_block, so that it stores an array similar to the return value of the node_get_types() core function.
the second seems simpler and wiser since there are multiple calls to variable_get that would need to "normalize" to a core function's return value. i'll try to whip up a patch later on, but if anyone else wants to throw one out, feel free! :)
Comment #8
nath commentedI agree, the second way is the one to go.
Comment #9
spidermanok i've done a fairly major overhaul of hook_block here, and everything appears to be working for me, whether i have set the related_block_types variable or not. the one significant change here is that i've made the default behaviour to show the related_block for *no* node types at all, in order to be consistent across the board.
previously, the block would use *all* node types by default, but if you saved the block configuration with no types selected, it would change to using *no* node types. this means that users will need to explicitly go to the block configuration page to select which node types they want to be used. this was a slightly easier way to go than making the default be all node types, but if people feel strongly this is a better default, we can rework this a bit.
@nath: let me know how the patch works for you :)
Comment #10
nath commentedOk, tested the patch, it works for me. I think that showing the block on all node types would be a more standard behavior but I'm ok with both ways.
Comment #11
dmuth commentedSubscribing.
I'd be happy to test a beta version of a new release of this module.
-- Doug
Comment #12
nath commentedCould we get this patch committed as well?
Comment #13
rhys commentedBeen committed. Sorry about the delay.
Comment #14
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.