You are here

private function Importer::getTarget in Feeds Paragraphs 8

Searches through nested Paragraphs entities for the target entities.

Parameters

EntityInterface $entity: A node or paragraph object.

FieldConfigInterface $targetConfig: A node or paragraph object.

array $result: The previous result.

Return value

Paragraph[] The found paragraphs.

3 calls to Importer::getTarget()
Importer::createParagraphs in src/Importer.php
Creates new Paragraphs entities, and marks others for values changes.
Importer::import in src/Importer.php
Importer::initHostParagraphs in src/Importer.php
Creates empty host Paragraphs entities or gets the existing ones.

File

src/Importer.php, line 244

Class

Importer

Namespace

Drupal\feeds_para_mapper

Code

private function getTarget($entity, $targetConfig, array $result = array()) {
  $path = $this->mapper
    ->getInfo($targetConfig, 'path');
  $last_key = count($path) - 1;
  $last_host_field = $path[$last_key]['host_field'];
  $target = $targetConfig
    ->getName();
  if (count($path) > 1) {
    $exist = $entity
      ->hasField($last_host_field);
    if ($exist) {
      $values = $entity
        ->get($last_host_field)
        ->getValue();
      foreach ($values as $value) {
        $result[] = $value['entity'];
      }
    }
    elseif ($exist = $entity
      ->hasField($target)) {
      $result[] = $entity;
    }
    else {
      foreach ($path as $host_info) {
        $field_exist = $entity
          ->hasField($host_info['host_field']);
        if ($field_exist) {
          $values = $entity
            ->get($host_info['host_field'])
            ->getValue();
          foreach ($values as $value) {
            $result = self::getTarget($value['entity'], $targetConfig, $result);
          }
        }
      }
    }
  }
  else {
    if (!$entity instanceof Paragraph && $entity
      ->hasField($path[0]['host_field'])) {
      $values = $entity
        ->get($path[0]['host_field'])
        ->getValue();
      foreach ($values as $value) {
        $result[] = $value['entity'];
      }
    }
    else {
      if ($entity instanceof Paragraph && ($exists = $entity
        ->hasField($target))) {
        $result[] = $entity;
      }
    }
  }
  return $result;
}