You are here

public static function MapperHelper::setFieldsInCommon in Feeds Paragraphs 8

Finds fields that share the same host as the target.

Parameters

FieldConfigInterface $field: The target fields.

array $fields: The other collected fields so far.

1 call to MapperHelper::setFieldsInCommon()
MapperHelper::getSubFields in src/Utility/MapperHelper.php

File

src/Utility/MapperHelper.php, line 190

Class

MapperHelper

Namespace

Drupal\feeds_para_mapper\Utility

Code

public static function setFieldsInCommon(FieldConfigInterface &$field, array &$fields) {
  foreach ($fields as $key => $other_field) {
    $other_info = $other_field
      ->get('target_info');
    $last_key = count($other_info->path) - 1;
    $others_host = $other_info->path[$last_key];
    $info = $field
      ->get('target_info');
    $current_host_key = count($info->path) - 1;
    $current_host = $info->path[$current_host_key];
    if ($others_host['host_field'] === $current_host['host_field']) {
      if (!isset($info->in_common)) {
        $info->in_common = array();
      }
      if (!isset($other_info->in_common)) {
        $other_info->in_common = array();
      }
      $other_field_in_common = array(
        'id' => $other_field
          ->id(),
        'name' => $other_field
          ->getName(),
      );
      $field_in_common = array(
        'id' => $field
          ->id(),
        'name' => $field
          ->getName(),
      );
      $info->in_common[] = $other_field_in_common;
      $field
        ->set('target_info', $info);
      $other_info->in_common[] = $field_in_common;
      $other_field
        ->set('target_info', $other_info);
    }
  }
}