You are here

public static function UserRole::targets in Feeds 8.3

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/UserRole.php, line 26

Class

UserRole
Defines a user role mapper.

Namespace

Drupal\feeds\Feeds\Target

Code

public static function targets(array &$targets, FeedTypeInterface $feed_type, array $definition) {
  $processor = $feed_type
    ->getProcessor();
  if (!$processor instanceof EntityProcessorInterface) {
    return $targets;
  }
  $field_definitions = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions($processor
    ->entityType(), $processor
    ->bundle());
  foreach ($field_definitions as $id => $field_definition) {
    if ($field_definition
      ->getType() == 'entity_reference' && $field_definition
      ->getSetting('target_type') == 'user_role') {
      if ($target = static::prepareTarget($field_definition)) {
        $target
          ->setPluginId($definition['id']);
        $targets[$id] = $target;
      }
    }
  }
}