The TOC display on category and container pages doesn't work (missing entirely, no matter how I configure things - at least on my upgraded site).

There are two problems in category_display module:

- In _category_display_children_reduce() the results of recursive calls are simply assigned to the $new_tree, where it should be merged with already existing items. The effect is, that each child-category processing wipes everything built before, and we end up with an empty array (and therefore no tree). This is fixed by simply changing the operator '=' to '+='.

- In _category_display_children_prune_tagged_content(), the criteria for 'content' is mere existence of *any* node of a given type tagged with a category (no matter revisions). If the site have just one category tagged with another category, then the type 'category' is considered to be content, and pruned out of the tree (leaving nothing to display). This behavior is counter-intuitive, and really hard to troubleshoot, so my fix is to check for 'category' and 'container' content types explicitly, and never prune them out.

As for WHY one might have a category tagged with another category (a natural question here) - it doesn't make much sense, but still it's possible to configure a container to accept categories as content, so it may be present in database on upgraded sites (like mine). Even if it was a single piece of unpublished garbage, forgotten and rotting somewhere for years, it'll take all the TOC displays down now. My fix avoids these issues.

Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JirkaRybka’s picture

FileSize
2.06 KB

Another very similar problem: With category_display module enabled, container pages show no node lists, no matter how the depth is set. This is due to variable type mismatch (array vs. object, making the later if ($node->category['depth']) { check always fail).

The code in question is actually located inside category.module, but is specific to category_display, so the fix is now a second hunk in this patch.

Jaza’s picture

Status: Needs review » Fixed
FileSize
2.33 KB

I wasn't able to reproduce your main problem, JirkaRybka - that of the TOC tree being completely missing. It showed up fine for me, for categories and containers, before applying your patch. However, your fixes do make sense, and the TOC also shows for me after applying, so I've committed it. :P

Re: node lists not showing on containers, I can confirm that this was a problem, and that your patch fixes it - thanks.

Please find attached the actual patch that I committed. It's almost the same as your final one, except that directly checking the node type is not the correct way of determining if a node type is a category or a container. Remember, any node type can have category or container 'behavior'.

You had:

if ($type != 'category' && $type != 'container' && /* ... */)

I committed:

$behavior = variable_get('category_behavior_'. $type, 0);
if (empty($behavior) && /* ... */)
JirkaRybka’s picture

I confirm that the finally committed version works fine for me. Indeed, your check is the correct one. (Category module is sometimes a bit hard to patch, due to the wide variety of features one never really used - every fix requires me to learn about things I never came across before :) ) And just for record - the steps to reproduce the TOC problem on beta2 would be along the lines of enabling 'category' content type as content in a container, and really assigning a category to another category as a tag (just one such assignment breaks TOC for whole site). It's edge case, and a bit silly too, I admit - but still my database have such garbage from the times of 4.7.x pre-launch evaluation of modules, despite my later numerous cleanups.

Note to others: This is just additional info, the problem is fixed already.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

JirkaRybka’s picture

A follow-up is now included in #501378: PERFORMANCE! Central caching for category API functions, proposing removal of the query, as the $behavior check is sufficient by itself.

nruest’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0-rc2
Status: Closed (fixed) » Active

I used this patch in on a site using the 6.x-2.0-beta2 version of Category, and it worked. However, I am working on a new site, and currently using the newest version of the module - 6.x-2.0-rc2. I am unable to get the ToC to display, as I was on the previous site before the patch was applied. Was this patch committed to head for the newest version of the module?