You are here

function feeds_para_mapper_create_paragraphs in Feeds Paragraphs 7

Creates new Paragraphs entities, and marks others for values changes.

Parameters

object $entity: The entity that is being edited or created.

array $mapping: Information about the target field and the target paragraph.

array $slices: The sliced values based on user choice & the field cardinality.

Return value

array The created Paragraphs entities based on the $slices

1 call to feeds_para_mapper_create_paragraphs()
feeds_para_mapper_init_host_paragraphs in ./feeds_para_mapper.module
Creates empty host Paragraphs entities or gets the existing ones.

File

./feeds_para_mapper.module, line 743
Allows feeds to import content to Paragraphs' fields.

Code

function feeds_para_mapper_create_paragraphs($entity, array $mapping, array $slices) {
  $items = array();
  for ($i = 0; $i < count($slices); $i++) {
    $should_create = feeds_para_mapper_should_create_new($entity, $mapping, $slices, $slices[$i]);
    if (!$should_create) {
      return $items;
    }
    if ($i === 0) {

      // Create the first host Paragraphs entity/entities.
      $par = feeds_para_mapper_create_parents($mapping, $entity);
    }
    else {

      // Instead of creating another series of host entity/entities,
      // duplicate the last created host entity.
      $attached_targets = feeds_para_mapper_get_target_paragraph($entity, $mapping);
      $last = $attached_targets[count($attached_targets) - 1];
      $par = feeds_para_mapper_duplicate_existing($mapping, $entity, $last);
    }
    if ($par) {
      $items[] = array(
        'paragraph' => $par,
        'value' => $slices[$i],
      );
    }
  }
  return $items;
}