You are here

private function Importer::initHostParagraphs in Feeds Paragraphs 8

Creates empty host Paragraphs entities or gets the existing ones.

Return value

array The newly created paragraphs items.

1 call to Importer::initHostParagraphs()
Importer::import in src/Importer.php

File

src/Importer.php, line 196

Class

Importer

Namespace

Drupal\feeds_para_mapper

Code

private function initHostParagraphs() {
  $attached = NULL;
  $should_create = FALSE;
  $slices = $this
    ->sliceValues();

  // If the node entity is new, find the attached (non-saved) Paragraphs:
  if ($this->entity
    ->isNew()) {

    // Get the existing Paragraphs entity:
    $attached = $this
      ->getTarget($this->entity, $this->target);
  }
  else {

    // Load existing paragraph:
    $attached = $this
      ->loadTarget($this->entity, $this->target);
  }
  if (count($attached)) {

    // Check if we should create new Paragraphs entities:
    $should_create = $this
      ->shouldCreateNew($attached[0], $slices);
  }
  if (count($attached) && !$should_create) {

    // If we loaded or found attached Paragraphs entities,
    // and don't need to create new entities:
    $items = $this
      ->updateParagraphs($attached, $slices);
  }
  elseif (count($attached) && $should_create) {

    // If we loaded or found attached Paragraphs entities,
    // and we DO NEED to create new entities:
    $items = $this
      ->appendParagraphs($attached, $slices);
  }
  else {

    // We didn't find any attached paragraph.
    // Get the allowed values per each paragraph entity.
    $items = $this
      ->createParagraphs($this->entity, $slices);
  }
  return $items;
}