0

I have a content type with a term reference field. I want to give user a convenient way of grouping multiple nodes of that type together. I see it like this:

  1. The user creates a first node
  2. When he goes to a node page, he sees a link "subjoin another document"
  3. After pressing it the taxonomy term creation form is shown, user fills required fields
  4. After saving the term he gets redirected to node creation form
  5. Second node is created, taxonomy term fields of both nodes point to newly created taxonomy term

What puzzles me is how it's best to implement such a multiphase logic in Drupal, when we need to guide the user through several unrelated forms.

1

I'm not sure, but you might find References and Relation module useful for this.

  • Completely forgot about the relation module! Many thanks. I see there is great progress since last spring. Will try to adapt a relation-select module, it's demonstrated in this great screencast: dev.nodeone.se/en/relation-select – Dmitry Vyal Apr 25 '12 at 10:40
0

In the end I implemented this functionality in a custom module. Together with prepopulate it allows to conveniently link nodes together without manually creating taxonomy terms.

function mymodule_menu() {
  $items = array();
  $items['continue_with/%/%'] = array(
    'title' => 'Continue with',
    'description' => 'Creates new story and links existent material to it',
    'page callback' => 'vidsboku_custom_continue_with',
    'page arguments' => array(1,2),
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function my_module_continue_with($content_type, $nid) {
  $existing = node_load($nid);

  if(!is_object($existing)) {
    drupal_goto("");
  }

  if (empty($existing->field_story)) {
    if (!node_access('update', $existing)  || !(user_access('administer taxonomy') || user_access('edit terms in 4'))) {
      drupal_set_message('Insufficient permissions','error');
      drupal_goto("");
      return;
    }

    $term = new stdClass();
    $term->vid = 4; // Vocabulary ID for Story
    $term->name = $existing->title; // Term Name

    taxonomy_term_save($term);
    $tid = $term->tid;

    $existing->field_story = array('und' => array(0 => array('tid' => $tid)));
    node_save($existing);
  } else
    $tid = $existing->field_story['und'][0]['tid'];

  drupal_goto('node/add/' . $content_type, array('query' =>
                                                  array('edit[field_story][und]' => $tid)));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.