You are here

public static function MapperHelper::getTargets in Feeds Paragraphs 8

Return value

FieldConfigInterface[]

File

src/Utility/MapperHelper.php, line 13

Class

MapperHelper

Namespace

Drupal\feeds_para_mapper\Utility

Code

public static function getTargets($entityType, $bundle, $with_path = TRUE) {
  $mapper = new static();
  $paragraphs_fields = $mapper
    ->findParagraphsFields($entityType, $bundle);
  $fields = array();
  foreach ($paragraphs_fields as $paragraphs_field) {
    $fields += self::getSubFields($paragraphs_field, $with_path);
  }

  // Remove the fields that don't support feeds:
  $targets_manager = \Drupal::service('plugin.manager.feeds.target');
  $definitions = $targets_manager
    ->getDefinitions();
  $supported = array_keys($definitions);
  $fields = array_filter($fields, function ($item) use ($supported) {
    $type = $item
      ->getType();
    return in_array($type, $supported);
  });

  // Add some info the field info object:
  $prepared = array();
  foreach ($fields as $field) {
    foreach ($definitions as $name => $plugin) {
      if ($name === $field
        ->getType()) {
        self::updateInfo($field, "plugin", $plugin);
        self::updateInfo($field, "class", $plugin['class']);
        self::updateInfo($field, "type", $field
          ->getType());
        $prepared[] = $field;
      }
    }
  }
  return $prepared;
}