From e2973d13ef59c0e8a9e6d9d4de81a97d994f114e Mon Sep 17 00:00:00 2001 From: twistor <twistor@473738.no-reply.drupal.org> Date: Fri, 10 Apr 2015 17:24:32 -0700 Subject: [PATCH] Issue #1815070 by twistor, joelpittet: No more mapping for numeric (boolean, decimal, integer, floats, and lists of them) fields --- mappers/list.inc | 63 ++++++++++++++++++++++++++++++++++++++++++++++ mappers/number.inc | 3 --- mappers/text.inc | 1 - 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 mappers/list.inc diff --git a/mappers/list.inc b/mappers/list.inc new file mode 100644 index 00000000..6a8a1687 --- /dev/null +++ b/mappers/list.inc @@ -0,0 +1,63 @@ +<?php + +/** + * @file + * On behalf implementation of Feeds mapping API for list.module. + */ + +/** + * Implements hook_feeds_processor_targets_alter(). + * + * @see FeedsProcessor::getMappingTargets() + */ +function list_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { + foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { + $info = field_info_field($name); + + switch ($info['type']) { + + case 'list_integer': + case 'list_float': + $targets[$name] = array( + 'name' => check_plain($instance['label']), + 'callback' => 'number_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + ); + break; + + case 'list_boolean': + $targets[$name] = array( + 'name' => check_plain($instance['label']), + 'callback' => 'list_feeds_set_boolean_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + ); + break; + + case 'list_text': + $targets[$name] = array( + 'name' => check_plain($instance['label']), + 'callback' => 'text_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + ); + break; + } + } +} + +/** + * Callback for setting list_boolean fields. + */ +function list_feeds_set_boolean_target(FeedsSource $source, $entity, $target, array $values, array $mapping = array()) { + $field = isset($entity->$target) ? $entity->$target : array(LANGUAGE_NONE => array()); + + foreach ($values as $value) { + + if (is_object($value) && ($value instanceof FeedsElement)) { + $value = $value->getValue(); + } + + $field[LANGUAGE_NONE][] = array('value' => (int) (bool) $value); + } + + $entity->$target = $field; +} diff --git a/mappers/number.inc b/mappers/number.inc index 338d5691..2b9c4368 100644 --- a/mappers/number.inc +++ b/mappers/number.inc @@ -12,9 +12,6 @@ */ function number_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { $numeric_types = array( - 'list_integer', - 'list_float', - 'list_boolean', 'number_integer', 'number_decimal', 'number_float', diff --git a/mappers/text.inc b/mappers/text.inc index 235aea3a..89a03ff1 100644 --- a/mappers/text.inc +++ b/mappers/text.inc @@ -12,7 +12,6 @@ */ function text_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { $text_types = array( - 'list_text', 'text', 'text_long', 'text_with_summary', -- GitLab