I have a hierarchy where the nodes can have a end term but not it's ancestors, so the count doesn't work for me and neither the feature of hide unused terms.

So I made a patch to include the count of descendants.

Comments

dstol’s picture

Status: Active » Needs work

Thanks, why don't you reroll it with an administrative option to include descendants or not.

john.money’s picture

Status: Needs review » Needs work
StatusFileSize
new2.83 KB

The original patch works but then makes the taxonomy_term_count_nodes() call redundant. My attached patch does a couple things:

  • creates a new setting display_num_descendants, not to be confused with display_descendants. This setting will include the count of descendant nodes using the core taxonomy module's taxonomy_term_count_nodes function if display_num is also set.
  • changes the description for display_descendants to reflect it applies to changing the path

Here's a chart of possible options. There may be more permutations:

Setting ==> display_num display_num_descendants display_descendents
Don't show count
Show count current term only x
Show count current term + descendants x x
Don't show count + alter path x
Show count current term + descendants + alter path x x

Patched against 6.x-2.x-dev (2011-Dec-02).

john.money’s picture

Status: Needs work » Needs review

Changing status to needs review

The last submitted patch, taxonomy_menu-display_descendants.patch, failed testing.

johnv’s picture

Title: Count of nodes should include descendants » 'Display number of items': Node count should include descendants

Marked #1337012: hierarchical taxonomy counts as a duplicate.
It contains a different solution. Not sure if it is better or compatible:

somewhere in function _taxonomy_menu_item there should perhaps be something like this:

	if ($num == 0) {
		$terms=_taxonomy_term_children($item['tid']);
		out($terms);
		foreach ($terms as $tid) {
			$num=$num+taxonomy_term_count_nodes($tid);
		}
	}

this way, the parent terms menu items of a hierachy will have a number that is the sum of the count of the children instead of (0) as is now.

johnv’s picture

stewart.adam’s picture

Version: 6.x-2.9 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.32 KB

Attached patch adds a new checkbox "Include items belonging to child terms in number counts" (defaults to disabled) which enables the inclusion of child terms' items in the node count.

Aurous’s picture

Status: Needs work » Fixed

Patch by stewart.adam works perfectly fine.

Aurous’s picture

Status: Needs review » Needs work

Please ignore previous post - one issue I am facing with stewart.adam's patch is that if the term reference node is deleted - the counter doesn't change for parent term, but only changes for child term.

stewart.adam’s picture

Status: Fixed » Needs work

To make sure I understood correctly:

  • Taxonomy term structure is Parent -> Child
  • Node 1 is tagged with term "Parent"
  • Node 2 is tagged with term "Child"

In this scenario deleting Node 2 updates the counter for the Child but not Parent term?

L.A.’s picture

The patch #7 is only working for the first child...

Eg. if I have this structure (standard "display number of items"):

-> Main (0)
     -> Sub1 (5)
     -> Sub2 (0)
          -> SubSub1 (3)
          -> SubSub2 (2)
    -> Sub3 (5)

the patch shows "Main (10)", so it doesn't count SubSub1 and SubSub2...

Besides this, I think the number of items should be shown like this:

-> Main (0/15)
     -> Sub1 (5)
     -> Sub2 (0/5)
          -> SubSub1 (3)
          -> SubSub2 (2)
    -> Sub3 (5)
slurpee’s picture

Issue summary: View changes

Hello from Drupal's GSoC 2014 team. Google Summer of Code (GSoC)? - an annual program for university students organized by Google with projects managed by open source organization mentors such as us (Drupal!).

We're currently browsing the issue queue looking for projects. Do you think this issue/project is worth a student spending a summer on it and being paid by Google? If so, are you interested in mentoring the student? Learn more about Summer of Code and how to get involved at links below. We're submitting our Summer of Code application to Google in just over 24 hours and looking for last minute ideas. Please respond quickly if you're interested.

Group to join - https://groups.drupal.org/google-summer-code

Ideas for projects for Summer of Code 2014 - https://groups.drupal.org/node/404778

GSoC Homepage http://www.google-melange.com/gsoc/homepage/google/gsoc2014

Google's Summer of Code 2014 Announcement - http://google-opensource.blogspot.com/2014/02/mentoring-organization-app...

parasolx’s picture

This patch already in 2 years ago and none of solution come out to let it commit in current version. Or does it plan to move into new major version?

I patch and it works successfully.

zionduc’s picture

Hello,
I'm just thinking if taxonomy_get_tree() wouldn't be better instead of taxonomy_get_children()?
So

$terms = taxonomy_get_tree($item['vid'], $item['tid']);

instead of

$terms = taxonomy_get_children($item['tid']);
Yuri’s picture

Any updates here?

Anonymous’s picture

Patch #7 worked for me on current dev, with a litle difference in lines. I am not a coder, maybe someone can make a new patch?

Why is the status 'needs work' and not 'needs review'?

rimen’s picture

My patch.
New option like in #7 with correct update node counts in parent terms (see #9)

Before mark as tested this logic must moved in taxonomy_menu_translated_menu_link_alter() allso.

makbay’s picture

#17 worked for me and I applied the same logic into function taxonomy_menu_translated_menu_link_alter() and it also worked.

SilviuChingaru’s picture

Status: Needs work » Needs review
StatusFileSize
new3.77 KB

Made patch from #17 apply against latest dev version. Applied the same concept to taxonomy_menu_translated_menu_link_alter().

SilviuChingaru’s picture

Status: Needs review » Reviewed & tested by the community
chris matthews’s picture

Would it be possible to commit the patch in #19 to 7.x-1.x-dev and tag a 7.x-1.6 release? Maybe some of the patches that need review can get in this release as well.

andrey.troeglazov’s picture

Assigned: Unassigned » andrey.troeglazov

  • fiftyz authored c46a051 on 7.x-1.x
    Issue #1064510 by john.money, fiftyz, stewart.adam, juanjo_vlc, rimen,...
andrey.troeglazov’s picture

Status: Reviewed & tested by the community » Fixed

For me its ok, I have commited the last patch but will be good if smn can double check it.

andrey.troeglazov’s picture

Status: Fixed » Closed (fixed)

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