You are here

public static function WrapperTarget::targets in Feeds Paragraphs 8

Returns the targets defined by this plugin.

Parameters

\Drupal\feeds\TargetDefinitionInterface[] $targets: An array of targets.

\Drupal\feeds\FeedTypeInterface $feed_type: The feed type object.

array $definition: The plugin implementation definition.

Overrides FieldTargetBase::targets

File

src/Feeds/Target/WrapperTarget.php, line 83

Class

WrapperTarget
Defines a wrapper target around a paragraph bundle's target field.

Namespace

Drupal\feeds_para_mapper\Feeds\Target

Code

public static function targets(array &$targets, FeedTypeInterface $feed_type, array $definition) {
  $processor = $feed_type
    ->getProcessor();
  $entity_type = $processor
    ->entityType();
  $bundle = $processor
    ->bundle();

  /**
   * @var Mapper $mapper
   */
  $mapper = \Drupal::service('feeds_para_mapper.mapper');
  $sub_fields = $mapper
    ->getTargets($entity_type, $bundle);
  foreach ($sub_fields as $field) {
    $field
      ->set('field_type', 'entity_reference_revisions');
    $wrapper_target = self::prepareTarget($field);
    if (!isset($wrapper_target)) {
      continue;
    }
    $properties = $wrapper_target
      ->getProperties();
    $mapper
      ->updateInfo($field, 'properties', $properties);
    $wrapper_target
      ->setPluginId("wrapper_target");
    $path = $mapper
      ->getInfo($field, 'path');
    $last_host = end($path);
    $wrapper_target
      ->setPluginId("wrapper_target");
    $id = $last_host['bundle'] . "_" . $field
      ->getName();
    $exist = isset($targets[$id]);
    $num = 0;
    while ($exist) {
      $num++;
      $id .= "_" . $num;
      $exist = isset($targets[$id]);
    }
    $targets[$id] = $wrapper_target;
  }
}