You are here

function taxonomy_node_import_defaults in Node import 6

Implementation of hook_node_import_defaults().

File

supported/taxonomy.inc, line 430
Support file for the core taxonomy module.

Code

function taxonomy_node_import_defaults($type, $defaults, $fields, $map) {
  $form = array();

  // Import taxonomy vocabularies.
  if ($type == 'vocabulary') {
    $form['nodes'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Content types'),
      '#default_value' => isset($defaults['nodes']) ? $defaults['nodes'] : array(),
      '#options' => array_map('check_plain', node_get_types('names')),
    );
    $options = array(
      'tags' => t('Tags'),
      'multiple' => t('Multiple select'),
      'required' => t('Required'),
    );
    foreach ($options as $key => $title) {
      $form[$key] = array(
        '#title' => $title,
        '#type' => 'radios',
        '#options' => array(
          '0' => t('No'),
          '1' => t('Yes'),
        ),
        '#default_value' => isset($defaults[$key]) ? $defaults[$key] : '0',
      );
    }
    $form['weight'] = array(
      '#title' => t('Weight'),
      '#type' => 'weight',
      '#default_value' => isset($defaults['weight']) ? $defaults['weight'] : 0,
    );
    $form['hierarchy'] = array(
      '#title' => t('Hierarchy'),
      '#type' => 'radios',
      '#options' => array(
        '0' => t('Disabled'),
        '1' => t('Single'),
        '2' => t('Multiple'),
      ),
      '#default_value' => isset($defaults['hierarchy']) ? $defaults['hierarchy'] : '0',
    );
  }
  else {
    if (strpos($type, 'term:') === 0) {
      $types = node_import_types();
      $vocab = $types[$type]['vocabulary'];
      $form['vocabulary'] = array(
        '#type' => 'item',
        '#title' => t('Vocabulary'),
        '#value' => check_plain($vocab->name),
      );
      $options = array();
      foreach (taxonomy_get_tree($vocab->vid) as $term) {
        $choice = new stdClass();
        $choice->option = array(
          $term->tid => str_repeat('-', $term->depth) . $term->name,
        );
        $options[] = $choice;
      }
      if ($vocab->hierarchy > 0) {
        $form['parent'] = array(
          '#type' => 'select',
          '#title' => t('Parents'),
          '#multiple' => $vocab->hierarchy == 2,
          '#options' => array_merge(array(
            '' => '<' . t('root') . '>',
          ), $options),
          '#default_value' => isset($defaults['parent']) ? $defaults['parent'] : '',
        );
      }
      $form['relations'] = array(
        '#type' => 'select',
        '#title' => t('Related terms'),
        '#multiple' => TRUE,
        '#options' => array_merge(array(
          '' => '<' . t('none') . '>',
        ), $options),
        '#default_value' => isset($defaults['relations']) ? $defaults['relations'] : '',
      );
      $form['synonyms'] = array(
        '#type' => 'textarea',
        '#title' => t('Synonyms'),
        '#default_value' => isset($defaults['synonyms']) ? $defaults['synonyms'] : '',
      );
      $form['weight'] = array(
        '#title' => t('Weight'),
        '#type' => 'textfield',
        '#size' => 6,
        '#default_value' => isset($defaults['weight']) ? $defaults['weight'] : 0,
      );
    }
    else {
      if (($node_type = node_import_type_is_node($type)) !== FALSE) {

        // Copy from taxonomy_form_alter().
        $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node_type);
        while ($vocabulary = db_fetch_object($c)) {
          if ($vocabulary->tags) {
            $form['taxonomy:' . $vocabulary->vid] = array(
              '#type' => 'textfield',
              '#title' => $vocabulary->name,
              '#default_value' => isset($defaults['taxonomy:' . $vocabulary->vid]) ? $defaults['taxonomy:' . $vocabulary->vid] : '',
              '#autocomplete_path' => 'taxonomy/autocomplete/' . $vocabulary->vid,
            );
          }
          else {
            $form['taxonomy:' . $vocabulary->vid] = taxonomy_form($vocabulary->vid, isset($defaults['taxonomy:' . $vocabulary->vid]) ? $defaults['taxonomy:' . $vocabulary->vid] : 0);
          }
        }
      }
    }
  }
  return $form;
}