You are here

function node_import_fields in Node import 6

Same name and namespace in other branches
  1. 5 node_import.api.inc \node_import_fields()

Returns a list of available content fields for given node_import type.

Parameters

$type: String. The node_import type.

$reset: Boolean. If TRUE, the internal cache is rebuilt.

Return value

Array of fields. See hook_node_import_fields().

Related topics

6 calls to node_import_fields()
node_import_add_form in ./node_import.admin.inc
Creates a new import task by letting the user fill in a wizard.
node_import_add_form_validate_next in ./node_import.admin.inc
node_import_automap in ./node_import.inc
Return an autodetected mapping for given headers and content type.
node_import_create in ./node_import.inc
Create a new object of specified $type.
node_import_create_user in supported/user.inc
Create a new user.

... See full list

File

./node_import.inc, line 165
Public API of the Node import module.

Code

function node_import_fields($type, $reset = FALSE) {
  static $fields;
  if (!isset($fields[$type]) || $reset) {
    $defaults = array(
      'title' => '',
      'tips' => array(),
      'group' => '',
      'module' => '',
      'weight' => 0,
      'is_mappable' => TRUE,
      'map_required' => FALSE,
      'has_multiple' => FALSE,
      'multiple_separator' => variable_get('node_import:multiple_separator', '||'),
      'has_hierarchy' => FALSE,
      'hierarchy_separator' => variable_get('node_import:hierarchy_separator', '>>'),
      'hierarchy_reverse' => FALSE,
      'input_format' => '',
      'preprocess' => array(),
      'allowed_values' => array(),
      'default_value' => NULL,
      'allow_empty' => FALSE,
      'map_required' => FALSE,
      'is_checkboxes' => FALSE,
    );
    $fields[$type] = (array) module_invoke_all('node_import_fields', $type);
    foreach ($fields[$type] as $fieldname => $fieldinfo) {

      // Merge sane defaults.
      $fields[$type][$fieldname] = $fieldinfo = array_merge($defaults, $fieldinfo);

      // Add preprocessors for builtin input_formats.
      if (!empty($fieldinfo['allowed_values'])) {
        $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_values';
        $s = '';
        foreach ($fieldinfo['allowed_values'] as $key => $value) {
          if (drupal_strlen($s) > 60) {
            $s .= ', …';
            break;
          }
          $s .= ($s == '' ? '' : ', ') . check_plain(drupal_strtolower($key)) . ': ' . check_plain(drupal_strtolower($value));
        }
        $fields[$type][$fieldname]['tips'][] = t('Allowed values (!values).', array(
          '!values' => $s,
        ));
      }
      switch ($fieldinfo['input_format']) {
        case 'boolean':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_boolean';
          $fields[$type][$fieldname]['tips'][] = t('Boolean (0/1, off/on, no/yes, false/true).');
          break;
        case 'date':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_date';
          $fields[$type][$fieldname]['tips'][] = t('Date ("YYYY-MM-DD HH:MM" or specified custom format).');
          break;
        case 'email':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_email';
          break;
        case 'filepath':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_filepath';
          break;
        case 'node_reference':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_node_reference';
          $fields[$type][$fieldname]['tips'][] = t('Node reference (by nid or title).');
          break;
        case 'user_reference':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_user_reference';
          $fields[$type][$fieldname]['tips'][] = t('User reference (by uid, name or mail).');
          break;
        case 'weight':
          $fields[$type][$fieldname]['preprocess'][] = 'node_import_check_weight';
          break;
      }
    }
    drupal_alter('node_import_fields', $fields[$type], $type);

    // Sort by weight.
    $count = 0;
    $max_count = count($fields[$type]) * 10;
    foreach ($fields[$type] as $fieldname => $fieldinfo) {
      $fields[$type][$fieldname]['weight'] += $count / $max_count;
      $count++;
    }
    uasort($fields[$type], 'node_import_sort');
  }
  return $fields[$type];
}