For Drupal7, we can possible deprecate this module. Instead of a term_node table, D7 stores term affiliations in Field storage. I think we can safely say that $delta=0 is the primary term.

What we might need is a dedicated widget (aka form element) which makes it clear and easy for editors to pick multiple terms and choose one as primary. Food for thought:

http://drupal.org/project/multiselect (a widget)
http://drupal.org/project/content_taxonomy (works with a variety of widgets)

Also, an upgrade path to field storage would be ideal. I guess it would run after the core upgrade to field storage and would fiddle with $delta values.

CommentFileSizeAuthor
#2 keywords.png21.53 KBspearhead93

Comments

brianV’s picture

Perhaps I am wrong... but the module will need tor remain, even just to provide an upgrade path to the D7 field storage.

I assume this could be as simple as a loop that does something like the following for each nid / vid with a primary term:

function primary_term_d7_update($nid, $vid, $tid) {
  $node = node_load($nid, $vid);

  $taxonomy = $node->taxonomy;
  foreach ($taxonomy as $delta=>$term) {
    if ($term->tid == $tid) {
      unset($taxonomy[$delta]);
      array_unshift($taxonomy, $term);
      break;
    }
  }
  $node->taxonomy = $taxonomy;
  node_save($node);
}

This would force the primary term to $node->taxonomy[0];. Following which, our widget could handle the rest and we could get rid of the database storage.

At the same time, this draws the assumption that no other contrib module cares about the position of a term in the taxonomy array; if another contrib module did, then these would conflict.

spearhead93’s picture

StatusFileSize
new21.53 KB

For a widget, I've implemented primary terms with jquery-asmselect: http://code.google.com/p/jquery-asmselect/. It works great and gives a good UI for end-users.
Primary term is the first one dragged at the top and is highlighted.
I'll investigate if it degrades better or not than multiselect.

gooddesignusa’s picture

spearhead93 any chance you could zip up the code so others can play around.

Taxoman’s picture

Title: D7 port » Port Primary_Term to Drupal 7
cimo75’s picture

Hi
I am interested in this one too, any news for D7?
tx
Simone

Katrina B’s picture

Related question: In D7, is it possible to set one Taxonomy term as the "primary term" -- so that if a node has several Taxonomy terms (in the same category) assigned to it, the desired one is used as part of the node's path or URL? (That would be my main reason for wanting a D7 version of Primary Term.)