drupaldrupal-7drupal-modulesdrupal-taxonomydrupal-nodes

Drupal map taxonomy terms to one specific role per node


The structure I need to realize:

  1. A node references multiple taxonomy terms of type person.
  2. A person plays one specific role per node.
  3. This role is different from this taxonomy terms role on a different node.
  4. A taxonomy term doesn't have to specifiy a role, so the role can be empty too.

An example to describe the desired behavior a bit better:

  1. A movie contains taxonomy terms as actors.
  2. An actor has the role 'Magneto' on node A and the role 'Gandalf' on node B.

Possible way of realization I can think of right now:

  1. Add a custom table nid_tid_role_mapping to the drupal database with the following fields: nid, tid, role_name
  2. Hook into node_presave and get all the actor taxonomy terms.
  3. Only get the ones of the following format "Actor Name (Role)" (f.e. "Ian McKellen (Magneto)")
  4. Add nid, tid and role to the table nid_tid_role_mapping
  5. After adding role, nid and tid, rename the taxonomy term back to "Actor Name".
  6. Add a special table to the node edit form, which lists the term name/role mapping of this node.

My approach seems like a little overkill to me. Is there a module which could help me with this? I wasn't able to find anything...


Solution

  • How about creating two vocabularies, an "actor" and a "character" vocabulary. The node of type "movie" references "character" (& "actor" maybe) and the vocabulary "character" references the "actor" vocabulary.

    Or another way to go is to create node-types instead of taxonomy terms and create relationships between them using the "entityreference" module. That is perhaps a better solution if you want to avoid getting several "James bond" terms (one for each actor).

    In the past i've tried the "relation" module aswell but it was to complex for my needs then and its not as popular as "entityreferences"