You are here

function node_import_defaults in Node import 6

Returns a list of default (form elements).

Parameters

$type: String. The node_import type.

$defaults: Array of currently filled in values.

$fields: Array of available fields.

$map: Array of how fields are mapped.

Return value

FAPI array. See hook_node_import_defaults().

Related topics

1 call to node_import_defaults()
node_import_add_form in ./node_import.admin.inc
Creates a new import task by letting the user fill in a wizard.

File

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

Code

function node_import_defaults($type, $defaults, $fields, $map) {
  if (!is_array($defaults)) {
    $defaults = array();
  }
  $form = (array) module_invoke_all('node_import_defaults', $type, $defaults, $fields, $map);
  foreach ($fields as $fieldname => $fieldinfo) {

    // Set #node_import-group if not set.
    if (isset($form[$fieldname]) && !isset($form[$fieldname]['#node_import-group'])) {
      $form[$fieldname]['#node_import-group'] = $fieldinfo['group'];
    }

    // Set #weight if not set.
    if (isset($form[$fieldname]) && !isset($form[$fieldname]['#weight'])) {
      $form[$fieldname]['#weight'] = $fieldinfo['weight'];
    }

    // Set #description if not set.
    if (isset($form[$fieldname]) && !isset($form[$fieldname]['#description'])) {
      if (count($fieldinfo['tips']) > 1) {
        $form[$fieldname]['#description'] = '<ul class="tips">';
        $form[$fieldname]['#description'] .= '<li>' . implode('</li><li>', $fieldinfo['tips']) . '</li>';
        $form[$fieldname]['#description'] .= '</ul>';
      }
      else {
        if (!empty($fieldinfo['tips'])) {
          $form[$fieldname]['#description'] = implode('', $fieldinfo['tips']);
        }
      }
    }

    // Set default_value as value.
    if (!empty($fieldinfo['default_value']) && !isset($form[$fieldname])) {
      $form[$fieldname] = array(
        '#type' => 'value',
        '#value' => $fieldinfo['default_value'],
      );
    }
  }
  drupal_alter('node_import_defaults', $form, $type, $defaults, $fields, $map);
  return $form;
}