summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt1
-rw-r--r--feeds.api.php10
-rw-r--r--feeds_import/feeds_import.feeds_importer_default.inc2
-rw-r--r--mappers/date.inc2
-rw-r--r--mappers/field.inc23
-rw-r--r--mappers/file.inc2
-rw-r--r--mappers/profile.inc2
-rw-r--r--mappers/taxonomy.inc2
-rw-r--r--plugins/FeedsNodeProcessor.inc22
-rw-r--r--plugins/FeedsProcessor.inc20
-rw-r--r--plugins/FeedsUserProcessor.inc4
-rw-r--r--tests/feeds_processor_node.test2
12 files changed, 55 insertions, 37 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 733945f..29f47c9 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@
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.
diff --git a/feeds.api.php b/feeds.api.php
index e203147..b3e7cd6 100644
--- a/feeds.api.php
+++ b/feeds.api.php
@@ -163,7 +163,7 @@ function hook_feeds_parser_sources_alter(&$sources, $content_type) {
* @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']);
}
@@ -205,6 +205,8 @@ function hook_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_nam
/**
* 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
@@ -213,8 +215,12 @@ function hook_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_nam
* 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'];
+ }
}
/**
diff --git a/feeds_import/feeds_import.feeds_importer_default.inc b/feeds_import/feeds_import.feeds_importer_default.inc
index 0f6e7fa..252f048 100644
--- a/feeds_import/feeds_import.feeds_importer_default.inc
+++ b/feeds_import/feeds_import.feeds_importer_default.inc
@@ -52,7 +52,7 @@ function feeds_import_feeds_importer_default() {
'unique' => 1,
),
),
- 'input_format' => 0,
+ 'input_format' => 'plain_text',
'author' => 0,
),
),
diff --git a/mappers/date.inc b/mappers/date.inc
index 807a6a7..e714a38 100644
--- a/mappers/date.inc
+++ b/mappers/date.inc
@@ -47,7 +47,7 @@ function date_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_nam
*
* @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)) {
diff --git a/mappers/field.inc b/mappers/field.inc
index 2f2057e..3a10441 100644
--- a/mappers/field.inc
+++ b/mappers/field.inc
@@ -36,7 +36,7 @@ function field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_na
$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(
@@ -53,12 +53,16 @@ function field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_na
*
* 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.
*
@@ -66,11 +70,17 @@ function field_feeds_set_target_numeric($entity, $target, $value) {
* 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);
@@ -81,6 +91,11 @@ function field_feeds_set_target($entity, $target, $value) {
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;
}
diff --git a/mappers/file.inc b/mappers/file.inc
index 1800e0b..bbb66da 100644
--- a/mappers/file.inc
+++ b/mappers/file.inc
@@ -37,7 +37,7 @@ function file_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_nam
* 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;
}
diff --git a/mappers/profile.inc b/mappers/profile.inc
index 33f6935..5dfd7e4 100644
--- a/mappers/profile.inc
+++ b/mappers/profile.inc
@@ -29,7 +29,7 @@ function profile_feeds_user_processor_targets_alter(&$targets) {
/**
* 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;
}
diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc
index c3f4eca..da021a8 100644
--- a/mappers/taxonomy.inc
+++ b/mappers/taxonomy.inc
@@ -62,7 +62,7 @@ function taxonomy_feeds_processor_targets_alter(&$targets, $entity_type, $bundle
*
* @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;
}
diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc
index f8eaceb..f815154 100644
--- a/plugins/FeedsNodeProcessor.inc
+++ b/plugins/FeedsNodeProcessor.inc
@@ -6,9 +6,6 @@
* Class definition of FeedsNodeProcessor.
*/
-// "Use the present default format"
-define('FEEDS_NODE_DEFAULT_FORMAT', -1);
-
/**
* Creates nodes from feed items.
*/
@@ -36,7 +33,6 @@ class FeedsNodeProcessor extends FeedsProcessor {
$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().
@@ -125,7 +121,6 @@ class FeedsNodeProcessor extends FeedsProcessor {
$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();
@@ -145,19 +140,6 @@ class FeedsNodeProcessor extends FeedsProcessor {
'#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',
@@ -207,7 +189,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
/**
* 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);
@@ -224,7 +206,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
}
break;
default:
- parent::setTargetElement($target_node, $target_element, $value);
+ parent::setTargetElement($source, $target_node, $target_element, $value);
break;
}
}
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index 3743b6d..621830e 100644
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -384,10 +384,10 @@ abstract class FeedsProcessor extends FeedsPlugin {
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;
@@ -408,6 +408,7 @@ abstract class FeedsProcessor extends FeedsPlugin {
return array(
'mappings' => array(),
'update_existing' => FEEDS_SKIP_EXISTING,
+ 'input_format' => NULL
);
}
@@ -429,6 +430,19 @@ abstract class FeedsProcessor extends FeedsPlugin {
),
'#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;
}
@@ -469,7 +483,7 @@ abstract class FeedsProcessor extends FeedsPlugin {
*
* @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':
diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc
index 7162133..d203e40 100644
--- a/plugins/FeedsUserProcessor.inc
+++ b/plugins/FeedsUserProcessor.inc
@@ -126,13 +126,13 @@ class FeedsUserProcessor extends FeedsProcessor {
/**
* 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;
}
}
diff --git a/tests/feeds_processor_node.test b/tests/feeds_processor_node.test
index e5b5615..968fc8e 100644
--- a/tests/feeds_processor_node.test
+++ b/tests/feeds_processor_node.test
@@ -162,7 +162,7 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$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');