You are here

public function Mapper::getSubFields in Feeds Paragraphs 8

Parameters

FieldDefinitionInterface $target:

array $result:

array $first_host:

Return value

array

1 call to Mapper::getSubFields()
Mapper::getTargets in src/Mapper.php

File

src/Mapper.php, line 103

Class

Mapper

Namespace

Drupal\feeds_para_mapper

Code

public function getSubFields($target, array $result = array(), array $first_host = array()) {
  $target_bundles = $this
    ->getEnabledBundles($target);
  foreach ($target_bundles as $target_bundle) {
    $sub_fields = $this->entityFieldManager
      ->getFieldDefinitions('paragraph', $target_bundle);
    $sub_fields = array_filter($sub_fields, function ($item) {
      return $item instanceof FieldConfigInterface;
    });
    foreach ($sub_fields as $machine_name => $sub_field) {

      // Initialize first host:
      if ($target
        ->getTargetEntityTypeId() !== 'paragraph') {
        $first_host = array(
          'bundle' => $target_bundle,
          'host_field' => $target
            ->getName(),
          'host_entity' => $target
            ->getTargetEntityTypeId(),
          'host_field_bundle' => $target
            ->get('bundle'),
        );
      }

      // If we found nested Paragraphs field,
      // loop through its sub fields to include them:
      $wrapped = $this
        ->isWrapped($sub_field, $first_host);
      if ($sub_field
        ->getType() === 'entity_reference_revisions' && !$wrapped) {
        $result = $this
          ->getSubFields($sub_field, $result, $first_host);
      }
      else {
        if ($sub_field
          ->getType() !== "feeds_item" && !$wrapped) {
          $sub_field = clone $sub_field;
          $host_allowed = $target
            ->getFieldStorageDefinition()
            ->getCardinality();
          $fieldAllowed = $sub_field
            ->getFieldStorageDefinition()
            ->getCardinality();
          $unlimited = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
          $has_settings = FALSE;
          if ($host_allowed === $unlimited || $host_allowed > 1) {
            if ($fieldAllowed === $unlimited || $fieldAllowed > 1) {
              $has_settings = TRUE;
            }
          }
          $this
            ->updateInfo($sub_field, "has_settings", $has_settings);
          $path = $this
            ->buildPath($sub_field, $first_host);
          $this
            ->updateInfo($sub_field, "path", $path);
          $this
            ->setFieldsInCommon($sub_field, $result);
          $result[] = $sub_field;
        }
        else {
          if ($wrapped) {
            $type = $sub_field->target_info->type;
            $sub_field
              ->set('field_type', $type);
            $result[] = $sub_field;
          }
        }
      }
    }
  }
  return $result;
}