Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX
---------------------------------
+- #953728 tristanoneil: Upgrade text formats, use on all processors.
- alex_b: Fix file mapper, add file mapper tests, generate flickr.xml and
files.csv dynamically.
- #953538 yhahn: Remove BOM from UTF-8 files.
* @see hook_feeds_parser_sources_alter().
* @see locale_feeds_get_source().
*/
-function my_source_get_source(FeedsSource $source, FeedsParserResult $result, $key) {
+function my_source_get_source($source, FeedsParserResult $result, $key) {
$item = $result->currentItem();
return my_source_parse_images($item['description']);
}
/**
* Example callback specified in hook_feeds_processor_targets_alter().
*
+ * @param $source
+ * Field mapper source settings.
* @param $entity
* An entity object, for instance a node object.
* @param $target
* The value to populate the target with.
*
*/
-function my_module_set_target($entity, $target, $value) {
+function my_module_set_target($source, $entity, $target, $value) {
$entity->$target['und'][0]['value'] = $value;
+ if (isset($source->importer->processor->config['input_format'])) {
+ $entity->$target['und'][0]['format'] =
+ $source->importer->processor->config['input_format'];
+ }
}
/**
'unique' => 1,
),
),
- 'input_format' => 0,
+ 'input_format' => 'plain_text',
'author' => 0,
),
),
*
* @todo Support array of values for dates.
*/
-function date_feeds_set_target($entity, $target, $feed_element) {
+function date_feeds_set_target($source, $entity, $target, $feed_element) {
list($field_name, $sub_field) = explode(':', $target, 2);
if (!($feed_element instanceof FeedsDateTimeElement)) {
if (is_array($feed_element)) {
$callback = 'field_feeds_set_target_numeric';
}
if (in_array($info['type'], $string_types)) {
- $callback = 'field_feeds_set_target';
+ $callback = 'field_feeds_set_target_text';
}
if (isset($callback)) {
$targets[$name] = array(
*
* Ensure that $value is a numeric to avoid database errors.
*/
-function field_feeds_set_target_numeric($entity, $target, $value) {
+function field_feeds_set_target_numeric($source, $entity, $target, $value) {
if (is_numeric($value)) {
- field_feeds_set_target($entity, $target, $value);
+ field_feeds_set_target($source, $entity, $target, $value, FALSE);
}
}
+function field_feeds_set_target_text($source, $entity, $target, $value) {
+ field_feeds_set_target($source, $entity, $target, $value, TRUE);
+}
+
/**
* Callback for mapping. Here is where the actual mapping happens.
*
* user has decided to map to and $value contains the value of the feed item
* element the user has picked as a source.
*/
-function field_feeds_set_target($entity, $target, $value) {
+function field_feeds_set_target($source, $entity, $target, $value, $input_format = FALSE) {
// Handle non-multiple value fields.
if (!is_array($value)) {
$value = array($value);
}
+
+ if ($input_format) {
+ if (isset($source->importer->processor->config['input_format'])) {
+ $format = $source->importer->processor->config['input_format'];
+ }
+ }
$info = field_info_field($target);
if (!is_array($v) && !is_object($v)) {
$field['und'][$i]['value'] = $v;
}
+ if ($input_format) {
+ if (isset($format)) {
+ $field['und'][$i]['format'] = $format;
+ }
+ }
if ($info['cardinality'] == 1) {
break;
}
* user has decided to map to and $value contains the value of the feed item
* element the user has picked as a source.
*/
-function file_feeds_set_target($entity, $target, $value) {
+function file_feeds_set_target($source, $entity, $target, $value) {
if (empty($value)) {
return;
}
/**
* Set the user profile target after import.
*/
-function profile_feeds_set_target($account, $target, $value) {
+function profile_feeds_set_target($source, $account, $target, $value) {
$account->{$target} = $value;
return $account;
}
*
* @todo Do not create new terms for non-autotag fields.
*/
-function taxonomy_feeds_set_target($entity, $target, $terms) {
+function taxonomy_feeds_set_target($source, $entity, $target, $terms) {
if (empty($terms)) {
return;
}
* Class definition of FeedsNodeProcessor.
*/
-// "Use the present default format"
-define('FEEDS_NODE_DEFAULT_FORMAT', -1);
-
/**
* Creates nodes from feed items.
*/
$node = new stdClass();
$node->type = $this->config['content_type'];
$node->changed = REQUEST_TIME;
- $node->format = ($this->config['input_format'] == FEEDS_NODE_DEFAULT_FORMAT) ? filter_fallback_format() : $this->config['input_format'];
$node->created = REQUEST_TIME;
node_object_prepare($node);
// Populate properties that are set by node_object_prepare().
$type = isset($types['article']) ? 'article' : key($types);
return array(
'content_type' => $type,
- 'input_format' => FEEDS_NODE_DEFAULT_FORMAT,
'expire' => FEEDS_EXPIRE_NEVER,
'author' => 0,
) + parent::configDefaults();
'#options' => $types,
'#default_value' => $this->config['content_type'],
);
- $format_options = array(FEEDS_NODE_DEFAULT_FORMAT => t('Default format'));
- global $user;
- $formats = filter_formats($user);
- foreach ($formats as $format) {
- $format_options[$format->format] = check_plain($format->name);
- }
- $form['input_format'] = array(
- '#type' => 'select',
- '#title' => t('Input format'),
- '#description' => t('Select the input format for the body field of the nodes to be created.'),
- '#options' => $format_options,
- '#default_value' => $this->config['input_format'],
- );
$author = user_load($this->config['author']);
$form['author'] = array(
'#type' => 'textfield',
/**
* Override setTargetElement to operate on a target item that is a node.
*/
- public function setTargetElement($target_node, $target_element, $value) {
+ public function setTargetElement(FeedsSource $source, $target_node, $target_element, $value) {
switch ($target_element) {
case 'created':
$target_node->created = feeds_to_unixtime($value, REQUEST_TIME);
}
break;
default:
- parent::setTargetElement($target_node, $target_element, $value);
+ parent::setTargetElement($source, $target_node, $target_element, $value);
break;
}
}
isset($targets[$this->id][$mapping['target']]['callback']) &&
function_exists($targets[$this->id][$mapping['target']]['callback'])) {
$callback = $targets[$this->id][$mapping['target']]['callback'];
- $callback($target_item, $mapping['target'], $value);
+ $callback($source, $target_item, $mapping['target'], $value);
}
else {
- $this->setTargetElement($target_item, $mapping['target'], $value);
+ $this->setTargetElement($source, $target_item, $mapping['target'], $value);
}
}
return $target_item;
return array(
'mappings' => array(),
'update_existing' => FEEDS_SKIP_EXISTING,
+ 'input_format' => NULL
);
}
),
'#default_value' => $this->config['update_existing'],
);
+ global $user;
+ $formats = filter_formats($user);
+ foreach ($formats as $format) {
+ $format_options[$format->format] = check_plain($format->name);
+ }
+ $form['input_format'] = array(
+ '#type' => 'select',
+ '#title' => t('Text format'),
+ '#description' => t('Select the input format for the body field of the nodes to be created.'),
+ '#options' => $format_options,
+ '#default_value' => isset($this->config['input_format']) ? $this->config['input_format'] : 'plain_text',
+ '#required' => TRUE,
+ );
return $form;
}
*
* @ingroup mappingapi
*/
- public function setTargetElement($target_item, $target_element, $value) {
+ public function setTargetElement(FeedsSource $source, $target_item, $target_element, $value) {
switch ($target_element) {
case 'url':
case 'guid':
/**
* Override setTargetElement to operate on a target item that is a node.
*/
- public function setTargetElement($target_user, $target_element, $value) {
+ public function setTargetElement(FeedsSource $source, $target_user, $target_element, $value) {
switch ($target_element) {
case 'created':
$target_user->created = feeds_to_unixtime($value, REQUEST_TIME);
break;
default:
- parent::setTargetElement($target_user, $target_element, $value);
+ parent::setTargetElement($source, $target_user, $target_element, $value);
break;
}
}
$this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $this->auth_user->name));
// Change input format.
- $this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => -1));
+ $this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => 'plain_text'));
// Import again.
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');