Hi,

most of my nodes have several taxonomy terms. And taxo breacrumb choose on of them, but not the more accurate.

How could i choose the "official" breadcrumb term for each node ?

Thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MGN’s picture

At the moment you can't really choose. It would be possible to develop this module further to allow finer control over the selection of the taxonomy term - perhaps with minimal performance hit. I'll keep this active for further consideration.

Right now this module does what I need it to, and I am short of time to develop solutions that I don't immediately need.

If anyone would like to try to propose a solution (i.e. submit a patch that provides this kind of control) and/or discuss the best way to do it, I would be happy to consider it further.

apaderno’s picture

Title: choose taxonomy term among several » Choose a taxonomy term among several
rmjiv’s picture

You might consider integrating with the Primary Term module

Katrina B’s picture

I'd like to know how to do this; I've installed Primary Term and Taxonomy Breadcrumb on my site, but I have no idea how to make them work together. (I'm a designer, not a programmer, so my knowledge of PHP is minimal at best.)

whytewolf’s picture

I have included a quick patch for this that i threw together, if it finds that $node->primaryterm is set it uses it for selecting the term that will be used, instead of the lightest term.

whytewolf’s picture

Version: 6.x-1.0 » 6.x-1.1
FileSize
1.84 KB

updated my last patch to work with the new version.

Alphabool’s picture

Status: Needs review » Active

Would it be possible to port this patch to the main module? I couldn't patch it using patch -p0 taxonomy_breadcrumb_pt_intergration.patch when I placed the patch in the sites/all/modules directory OR the sites/all/modules/taxonomy_breadcrumb directory. Then I tried just copying the changes you've made in the patch to taxonomy_breadcrumb.inc and taxonomy_breadcrumb.module by hand, but that screwed up taxonomy selection and I was getting lots of errors so I gave up and reverted.

This is a must-have feature when more than one vocabulary is applied to a node and would really improve this module, IMHO. I haven't gotten this to work yet, and I'd really like to.

I have 6.x-1.1 installed.

Thanks

whytewolf’s picture

strange. the second patch is the version for 1.1 and should be able to work from the sites/all/modules directory.I say it's odd cause I actually used this patch myself on 1.1 to transfer between my development system and a production system. I"ll look again to see if there is anything i can do.

MGN’s picture

Status: Active » Needs work

@whytewolf, thanks for contributing this. But rather than add new code that is specific to primary term (or any other contrib module), I would rather provide a more general mechanism (perhaps via drupal_alter) that would allow any module to alter the term used by taxonomy breadcrumb. This way, choosing the lightest term would remain as a default, but anyone could customize the behavior by implementing an appropriate hook.

What do you think about this? If you would like to produce a patch implementing this approach (or something similar) I would be happy to review it and get it committed.

Alphabool’s picture

@MGN If this very important feature was implemented by means of a general mechanism like you suggest here, would the Primary term module have to be changed at all to implement the functionality? I think that specific integration with Primary term is a great choice because Primary term is already doing exactly what we need.

@whytewolf I just successfully patched taxonomy_breadcrumb using your 6.x-1.1 patch (I'm running taxonomy_breadcrumb 6.x-1.1). The patch is wreaking havoc with primary term, however, because I'm getting the following errors:

warning: Illegal offset type in isset or empty in /sites/all/modules/primary_term/primary_term.module on line 38.
warning: Illegal offset type in isset or empty in /modules/taxonomy/taxonomy.module on line 1023.
warning: Illegal offset type in /modules/taxonomy/taxonomy.module on line 1024.
warning: Illegal offset type in /modules/taxonomy/taxonomy.module on line 1027.
warning: Illegal offset type in isset or empty in /modules/taxonomy/taxonomy.module on line 1023.
warning: Illegal offset type in /modules/taxonomy/taxonomy.module on line 1024.
warning: Illegal offset type in /modules/taxonomy/taxonomy.module on line 1027.

All those paths are relative to Drupal root.

I did not have these error beforehand. However, when I reversed your patch, I was still getting these errors when I posted content. I then disabled the primary term module and the errors disappeared. I was running the primary term module 6.x-1.0.

So I don't think the errors were caused by your patch, they seem to be caused by Primary term. I posted to the Primary term issue queue about this.

However, the patch was definitely doing something right, because the right vocabulary was being used when I posted content. However, it was selecting not displaying the right term for the content in that vocabulary.

So for a story whose taxonomy hierarchy looks like this:

Vocabulary: Primary Links
Term: Sections>Arts>Movies

Taxonomy breadcrumb displayed Home>>Sections>>News. Sections is the first term in the "Primary Links" vocabulary, and "News" is the first subterm of the "Sections" term. When I reverse your patch I get the correct taxonomy breadcrumb when it displays. But it doesn't display all the time, like it did with your patch. Again, Taxonomy breadcrumb 6.x-1.1 and Primary term 6.x-1.0.

MGN’s picture

@Alphabool, no, primary term would not have to be changed. Whytewolf's code could be placed within a custom module and enabled to provide the feature. The custom module would just implement the hook that would be offered by taxonomy breadcrumb. The nice thing about this approach is that if someone else wants to do it differently (not using primary term, but perhaps another module) they could implement the same hook. Given that primary term doesn't seem to be maintained anymore (last commit was in 2008), I am really hesitant to put any code into taxonomy breadcrumb that refers to that module.

Reading through the primary term code in cvs, i think the problem with Whytewolf's code is that $node->primaryterm is the term id, not the term object.
(object)array('tid' => $node->primaryterm) should be replaced (I think) with $node->primary_term (see below).

Attached is a patch that would let modules implementing modulename_taxonomy_breadcrumb_lightest term($term, $node = NULL) inspect the term that is being used to set the tax breadcrumb trail, and then alter or replace it with another term, as desired. $term is passed by reference, so the function just needs to alter this variable. $node is present on a node page, but not for the taxonomy term page.

Whytewolf's code would then be revised as follows (Note that this is untested)


function mymodule_taxonomy_breadcrumb_lightest_term_alter($term, $node = NULL) {
  if (isset($node->primary_term)) { 
    $term = $node->primary_term;	// Todo: would it be better to clone this object?
  }
}

If you already have a custom module that you use for customizing your site, just add this function to that file (and change mymodule to the real name of your module). If you don't, you'll need to create a very simple module. Just place this code in a file called mymodule.module and create a basic mymodule.info file (you can pattern it off of another drupal 6 .info file - keep it simple) and place them in a mymodule directory within your modules directory.

I haven't tested this, but think it should work for everyone!

Edits to fix two typos!

whytewolf’s picture

Status: Needs work » Needs review

the drupal_alter patch appears to work, tho the name of the function should be mymodule_taxonomy_breadcrumb_lightest_term_alter to work with drupal_alter but thats just a directions thing.
also I would recommend dropping the lightest off the alter as really this isn't altering the lightest function it's altering the $term variable

MGN’s picture

Thanks for testing and catching my mistakes. I agree, and will change the name to 'taxonomy_breadcrumb_term_alter' before committing.

Alphabool’s picture

Yeah you're absolutely right, @MGN, about Primary term - it's likely to fork and there's very little interest. As I said, it was also giving me errors. A good implementation of this functionality, I think, would by by the means of a custom module, as you suggest, but one that would include the logic to pick the term assigned to the node. I have only a themer's understanding of Drupal PHP but I'm looking forward to developing a module that would choose the term assigned to the passed node from the specific vocabulary that I want. The drupal_alter() would allow me to stick my hands in there and modify Taxonomy breadcrumb's $term before the breadcrumb is generated in _taxonomy_breadcrumb_generate_breadcrumb(), as I understand it. Since it's a custom module, one wouldn't need to be flexible, and as I don't think I'll ever change the name of the vocabulary I use for navigation and categorization, I could just hard-code that in to the module.

You mention that one might want to clone the $node->$primary_term object. I have been teaching myself PHP as I develop a theme and this will give me an opportunity to improve my PHP in the context of the building a rudimentary module, but could one pass a reference or the equivalent of a C++ pointer? If not, why clone the object? What does that achieve?

Finally, @whytewolf mentions that you should drop the _alter from mymodule_taxonomy_breadcrumb_lightest_term_alter(). I understand why one would drop off _lightest, because it isn't the lightest term, in fact, but when I checked out the drupal_alter() function in the Drupal API reference, @Mandaleem, in their comment, suggests using the nomenclature hook_TYPE_alter(). So if the type is _taxonomy_breadcrumb_term, then why drop the _alter?

This is a great addition; would you let us know when you commit it?

whytewolf’s picture

@alphabool sorry for the confusion, I wasn't asking that the _alter be removed. that part of the sentence was about what to remove _lightest from. it wouldn't have been proper to say type since it would be removed from both the function and the type. and the whole system is called an alter.

I actually suggested that in the documentation that @MGN add _alter to the function. to avoid confusion.

as for the error you were getting. @MGN is right, $node->primary_term should have been returned. I had used (object)array('tid'=>$node->primaryterm) to mimic the behavior of $term->tid

I can not say why that works for me and not others.

brianV’s picture

Hi all.

I am now maintaining Primary Term, and I've made a bunch of updates or improvements.

I would be interested in actually implementing an integration of some sort with Taxonomy Breadcrumb, since breadcrumbs are one of the planned use cases for PT.

Has this drupal_alter hook been committed yet?

Status: Active » Needs review
apaderno’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Issue summary: View changes
Status: Needs review » Closed (outdated)

I am closing this issue, which is for a not supported Drupal version.