i'm using the Feeds module to import nodes using a csv, and i'd like to populate the Summary field on import. It's not available in the ui, but i think it is supported in the field.inc file, i just don't know how to configure it.

does anyone have experience or could advise me on how i could accomplish this using Feeds or another tool?

thanks.

Comments

kalabro’s picture

It is not supported by Feeds out of the box. Here is an issue: #962912: Mapping to node summary
But you can alter feed targets to add this functionality:

/**
 * Implements hook_feeds_processor_targets_alter().
 */
function YOURMODULE_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  if ($entity_type == 'node') {
    if (isset($targets['body'])) {
      $field_body = field_info_field('body');
      if ($field_body['type'] == 'text_with_summary') {
        // Add summary target
        $targets['body:summary'] = array(
          'name' => $targets['body']['name'] . ': ' . t('Summary'),
          'description' => 'Field summary.',
          'callback' => 'YOURMODULE_set_target_summary',
          //'real_target' => 'body',
        );
        $targets['body']['name'] .= ': ' . t('Value');
      }
    }
  }
}

/**
 * Callback for mapping.
 */
function YOURMODULE_set_target_summary($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }
  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array($value);
  }

  $info = field_info_field($target);
  $cnt = count($value);
  for ($i = 0; $i < $cnt; $i++) {
    $v = $value[$i];
    $entity->body[LANGUAGE_NONE][$i]['summary'] = $v;
    if ($info['cardinality'] == 1) {
      break;
    }
  }
}

fureigh’s picture