function feeds_para_mapper_set_target in Feeds Paragraphs 7
Sets the values for the target field.
Parameters
\FeedsSource $source: The source instance.
object $entity: The entity that is being edited or created.
string $target: The target field that the source values are being mapped to.
array $values: The source field values.
array $mapping: Information about the target field and the target paragraph.
1 string reference to 'feeds_para_mapper_set_target'
File
- ./
feeds_para_mapper.module, line 492 - Allows feeds to import content to Paragraphs' fields.
Code
function feeds_para_mapper_set_target(\FeedsSource $source, $entity, $target, array $values, array $mapping) {
// check whether there are values:
$empty = feeds_para_mapper_is_empty($values);
if ($empty) {
return;
}
$mapping = feeds_para_mapper_init_mapping($entity, $mapping);
// Check if the field module support Feeds.
if (!function_exists($mapping['module_callback'])) {
$message = t('Field @field does not support Feeds', array(
'@field' => $mapping['field'],
));
drupal_set_message($message, 'error');
return;
}
// Create empty paragraphs or get the currently attached to the entity.
$paragraphs = feeds_para_mapper_init_host_paragraphs($entity, $mapping, $values);
foreach ($paragraphs as $item) {
// when the target field is nested, we need to get the correct entity for this field:
$paragraph = feeds_para_mapper_get_target_paragraph($item['paragraph'], $mapping, TRUE);
if (!count($paragraph)) {
continue;
}
$paragraph = $paragraph[0];
feeds_para_mapper_set_value($source, $entity, $paragraph, $mapping, $item['value']);
}
}