Hi,

This module currently uses taxonomy_get_parents() function to fetch the parents. This function only returns the first parent that is found for the term. So if I have a structure like this:

|- Parent_Term_1
|--- Term_A -- Associated to Node_1 and Node_2
|---|--- Term D Associated to Node_7
|--- Term_B -- Associated to Node_3
|---|--- Term E Associated to Node_8
|--- Term_C -- Associated to Node_4, Node_5 and Node_6

Using the 'Taxonomy parent term ID from URL' argument when viewing Node_7, it would only return the term ID for Term A. In my case I'd like to have it return the root parent term (Parent_Term_1).

By replacing the taxonomy_get_parents() function with taxonomy_get_parents_all() function, we would get all the parent terms that are set for the node.

I get it that this might not be the case everyone wants it, but it would be cool to have this as an option (at the contextual filter settings or something). Anyway, here's a mini-patch for this.

Comments

morgothz’s picture

Assigned: Unassigned » morgothz

Hi Sampo!
Thanks for your patch :-)

As you say is a good idea have this as an additional option at filter settings.
When I have a few minutes, I will include this option.

Thank you again!

morgothz’s picture

Status: Active » Needs review

New feature added! :-D

Added an option to argument settings, to get content from root parent terms.
Fixed on 7.x-1.1 module version.

Sampo, if you can prove it and give feedback I'd appreciate it.
Thanks for the idea and the patch, I have mentioned you in the commit message ;-)

isampo’s picture

Wow, that was fast! Thanks!

This seems to be working fine on node pages when the option "Load default filter from node page" is selected.

When the "Load default filter from term page" is also selected, the View doesn't fetch the contextual filter correctly since it only returns arg(2) (line 132).

Should we do something like this when viewing term pages:

$parents = (!empty($this->options['root_parent'])) ? taxonomy_get_parents_all(arg(2)) : taxonomy_get_parents(arg(2));

And then return the all the parents we got. I also made something custom to return all nodes if we're not on node page or Taxonomy page, but I think that's a feature that's not needed for this module.

morgothz’s picture

Hi iSampo!
Changes for term page case are made on development branch (7.x-1.x).
Again, if you can prove it and give feedback I'd appreciate it.

If everything is correct, and is not necessary to make further changes or add new additional features, a new version will be published.

Thanks for your help and your contributions.

isampo’s picture

Hi,

Tested this briefly with node+term pages and it seemed to be working exactly as it is supposed to.
The code for term pages looks also very good.

One side-note on this that you might want to mention on the README: When getting the root parent term for the View, the parent term needs to be selected on the node form. So if I'm selecting Term_D from example above, it won't give me the parent unless I have also selected the Parent_Term_1 from the dropdown. I used Hierarchical Select to force-select the term parent.