You are here

function icon_field_feeds_set_target in Icon API 8

Same name and namespace in other branches
  1. 7 modules/icon_field/icon_field.feeds.inc \icon_field_feeds_set_target()

Callback function to set value of a icon field.

1 string reference to 'icon_field_feeds_set_target'
icon_field_feeds_processor_targets_alter in modules/icon_field/icon_field.feeds.inc
Implements hook_feeds_processor_targets_alter().

File

modules/icon_field/icon_field.feeds.inc, line 56
icon_field.feeds.inc Feeds mapping implementation for the Icon Field module.

Code

function icon_field_feeds_set_target($source, $entity, $target, $value, $mapping) {

  // Don't do anything if we weren't given any data.
  if (empty($value)) {
    return;
  }

  // Assume that the passed in value could really be any number of values.
  if (is_array($value)) {
    $values = $value;
  }
  else {
    $values = array(
      $value,
    );
  }

  // Add in default values.
  $mapping += array(
    'term_search' => 'lullacons_pack1',
  );
  $iterator = 0;
  $field = isset($entity->{$target}) ? $entity->{$target} : array();
  $language = isset($mapping['language']) ? $mapping['language'] : \Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED;
  foreach ($values as $val) {
    $field[$language][$iterator]['bundle'] = $mapping['icon_bundle'];
    $field[$language][$iterator]['icon'] = $val;
    $iterator++;
  }

  // Add the field to the entity definition.
  $entity->{$target} = $field;
}