You are here

private function Importer::createParagraphs in Feeds Paragraphs 8

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

Parameters

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

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 Importer::createParagraphs()
Importer::initHostParagraphs in src/Importer.php
Creates empty host Paragraphs entities or gets the existing ones.

File

src/Importer.php, line 346

Class

Importer

Namespace

Drupal\feeds_para_mapper

Code

private function createParagraphs($entity, array $slices) {
  $items = array();
  for ($i = 0; $i < count($slices); $i++) {
    $should_create = $this
      ->shouldCreateNew($entity, $slices, $slices[$i]);
    if (!$should_create) {
      return $items;
    }
    if ($i === 0) {

      // Create the first host Paragraphs entity/entities.
      $par = $this
        ->createParents($entity);
    }
    else {

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