You are here

function taxonomy_node_import_fields in Node import 6

Same name and namespace in other branches
  1. 5 supported/taxonomy.inc \taxonomy_node_import_fields()

Implementation of hook_node_import_fields().

File

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

Code

function taxonomy_node_import_fields($type) {
  $fields = array();

  // Import taxonomy vocabularies.
  if ($type == 'vocabulary') {
    $fields['name'] = array(
      'title' => t('Vocabulary name'),
      'group' => t('Identification'),
      'module' => 'taxonomy',
      'map_required' => TRUE,
      'default_value' => '',
    );
    $fields['description'] = array(
      'title' => t('Description'),
      'group' => t('Identification'),
      'module' => 'taxonomy',
      'default_value' => '',
    );
    $fields['help'] = array(
      'title' => t('Help text'),
      'group' => t('Identification'),
      'module' => 'taxonomy',
      'default_value' => '',
    );
    $fields['nodes'] = array(
      'title' => t('Content types'),
      'group' => t('Content types'),
      'module' => 'taxonomy',
      'has_multiple' => TRUE,
      'is_checkboxes' => TRUE,
      'allowed_values' => node_get_types('names'),
    );
    $fields['tags'] = array(
      'title' => t('Tags'),
      'group' => t('Settings'),
      'module' => 'taxonomy',
      'input_format' => 'boolean',
    );
    $fields['multiple'] = array(
      'title' => t('Multiple select'),
      'group' => t('Settings'),
      'module' => 'taxonomy',
      'input_format' => 'boolean',
    );
    $fields['required'] = array(
      'title' => t('Required'),
      'group' => t('Settings'),
      'module' => 'taxonomy',
      'input_format' => 'boolean',
    );
    $fields['weight'] = array(
      'title' => t('Weight'),
      'group' => t('Settings'),
      'module' => 'taxonomy',
      'input_format' => 'weight',
    );
    $fields['hierarchy'] = array(
      'title' => t('Hierarchy'),
      'group' => t('Advanced settings'),
      'module' => 'taxonomy',
      'allowed_values' => array(
        '0' => t('Disabled'),
        '1' => t('Single'),
        '2' => t('Multiple'),
      ),
    );
  }
  else {
    if (strpos($type, 'term:') === 0) {
      $types = node_import_types();
      $vocab = $types[$type]['vocabulary'];
      $fields['vid'] = array(
        'is_mappable' => FALSE,
        'default_value' => $vocab->vid,
      );
      $fields['name'] = array(
        'title' => t('Term name'),
        'group' => t('Identification'),
        'module' => 'taxonomy',
        'map_required' => TRUE,
        'default_value' => '',
      );
      $fields['description'] = array(
        'title' => t('Description'),
        'group' => t('Identification'),
        'module' => 'taxonomy',
        'default_value' => '',
      );
      $fields['parent'] = array(
        'title' => t('Parents'),
        'group' => t('Advanced options'),
        'module' => 'taxonomy',
        'has_multiple' => FALSE,
        // Although all vocabs in Drupal6.x allow for multiple parents, we only allow one.
        'has_hierarchy' => TRUE,
        'input_format' => 'taxonomy_term',
        'vocabulary' => $vocab,
      );
      $fields['relations'] = array(
        'title' => t('Related terms'),
        'group' => t('Advanced options'),
        'module' => 'taxonomy',
        'has_multiple' => TRUE,
        'has_hierarchy' => TRUE,
        'input_format' => 'taxonomy_term',
        'vocabulary' => $vocab,
      );
      $fields['synonyms'] = array(
        'title' => t('Synonyms'),
        'group' => t('Advanced options'),
        'module' => 'taxonomy',
        'has_multiple' => TRUE,
        'multiple_separator' => ',',
      );
      $fields['weight'] = array(
        'title' => t('Weight'),
        'group' => t('Advanced options'),
        'module' => 'taxonomy',
        'input_format' => 'weight',
      );
    }
    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)) {
          $fields['taxonomy:' . $vocabulary->vid] = array(
            'title' => $vocabulary->name,
            'group' => t('Vocabularies'),
            'module' => 'taxonomy',
            'input_format' => 'taxonomy_term',
            'vocabulary' => $vocabulary,
            'has_multiple' => $vocabulary->multiple || $vocabulary->tags,
            'has_hierarchy' => $vocabulary->hierarchy > 0,
            'multiple_separator' => $vocabulary->tags ? ',' : '||',
          );
        }
      }
    }
  }
  return $fields;
}