create term using author name on bio creation?

eggthing - June 12, 2008 - 23:54

I'm able to create a title from authors name using the token module and automatic nodetitle.
Now I'd like to automatically create a taxonomy term for the authors name.
I tried using NAT but that doesn't associate the newly created term with the node.

I've got a hunch I can do something with computed field and content taxonomy, but I'm not sure what....

Any ideas?

Roundabout way

eggthing - June 21, 2008 - 01:19

Well I found a ridiculously roundabout way of doing it. I know...I know...but I needed it desperately and it works for now. Maybe someone can show me a better way eventually....

Install NAT, Usernode, CCK, Content Taxonomy, Bio.
Use this patch for taxonomy.module - http://drupal.org/files/issues/taxonomy_get_tid_by_name_0.patch
Assign NAT to usernode
Create a list style content taxonomy field in bio content type
Put this code into the default value of content taxo field under php code:

global $user;
$uname = $user->name;
$result = taxonomy_get_tid_by_name($uname);
settype ($result, "integer");
return array(array($result=> $result));

Use css to hide the content taxonomy field so the term gets inserted automatically and without user intervention.

As usernode is created automatically, thus NAT will automatically create the node term upon registration.
The first edit of the bio module assigns the author name to bio.

Grrrrrrrumble.... Whine...! It was real hard. There must be a more elegant solution....

Meg Lee Chin
http://megleechin.com

And even easier

eggthing - June 21, 2008 - 02:03

Using computed field is easier.

global $user;
  $term = array(
  'name' => $user->name,
  'vid' => 2,
  'description' => 'a term',
);
if ($term == 0) {
taxonomy_save_term($term);
}
$aname = taxonomy_get_tid_by_name($user->name);
settype ($aname, "integer");
$nodid = $node->nid;
db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nodid,  $aname);

Sigh....

Meg Lee Chin
http://megleechin.com

 
 

Drupal is a registered trademark of Dries Buytaert.