function languagefield_feeds_set_target in Custom Language field 7
Implements feed_set_target().
Parameters
$source Field mapper source settings.:
$entity The entity to map to.:
$target The target key on $entity to map to.:
$value The value to map. MUST be an array.:
Return value
entity
1 string reference to 'languagefield_feeds_set_target'
- languagefield_feeds_processor_targets_alter in ./
languagefield.feeds.inc - Implements feeds_processor_target_alter().
File
- ./
languagefield.feeds.inc, line 38 - A feeds mapper for language_field field of languagefield.module.
Code
function languagefield_feeds_set_target($source, $entity, $target, $value) {
if (empty($value)) {
return;
}
if (!is_array($value)) {
$value = array(
$value,
);
}
$info = field_info_field($target);
// Get lists of all languages and user languages.
$languages_all = _languagefield_options(LANGUAGEFIELD_LANGUAGES_ALL);
$languages_user = _languagefield_options(LANGUAGEFIELD_AUTHORS_DEFAULT);
// Iterate over all values.
$i = 0;
$field = isset($entity->{$target}) ? $entity->{$target} : array();
foreach ($value as $v) {
if (empty($v)) {
// No value;
}
elseif (isset($languages_all[$v])) {
$field[LANGUAGE_NONE][$i]['value'] = $v;
}
elseif (isset($languages_user[$v])) {
$field[LANGUAGE_NONE][$i]['value'] = $v;
}
else {
// No valid language code, search for language name?
$key = array_search($v, $languages_all);
if (!$key) {
$key = array_search($v, $languages_user);
}
if ($key) {
// Found, return language code.
$field[LANGUAGE_NONE][$i]['value'] = $key;
}
else {
// // Illegal value, pass anyway.
// $field[LANGUAGE_NONE][$i]['value'] = $v;
}
}
if ($info['cardinality'] == 1) {
break;
}
$i++;
}
$entity->{$target} = $field;
return $entity;
}