You are here

protected static function WrapperTarget::prepareTarget in Feeds Paragraphs 8

Prepares a target definition.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

Return value

\Drupal\feeds\FieldTargetDefinition The target definition.

Overrides FieldTargetBase::prepareTarget

1 call to WrapperTarget::prepareTarget()
WrapperTarget::targets in src/Feeds/Target/WrapperTarget.php
Returns the targets defined by this plugin.

File

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

Class

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

Namespace

Drupal\feeds_para_mapper\Feeds\Target

Code

protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
  $mapper = \Drupal::service('feeds_para_mapper.mapper');
  $field_type = $mapper
    ->getInfo($field_definition, 'type');
  $plugin = $mapper
    ->getInfo($field_definition, 'plugin');
  $path = $mapper
    ->getInfo($field_definition, 'path');
  if (!isset($field_type) || !isset($plugin)) {
    return null;
  }
  $class = $plugin['class'];
  $field_definition
    ->set('field_type', $field_type);
  $targetDef = $class::prepareTarget($field_definition);
  if (!isset($targetDef)) {
    return null;
  }
  $label = $field_definition
    ->getLabel();
  $label .= ' (';
  foreach ($path as $i => $host) {
    if ($i + 1 === count($path)) {
      $label .= $host['host_field'];
    }
    else {
      $label .= $host['host_field'] . ":";
    }
  }
  $label .= ')';
  $field_definition
    ->set('label', $label);
  $field_definition
    ->set('field_type', 'entity_reference_revisions');
  return $targetDef;
}