You are here

class UserFeed in Feeds 8.3

Alters the parsed result for the feeds importing users.

Hierarchy

  • class \Drupal\feeds_test_alter_source\EventSubscriber\UserFeed implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of UserFeed

1 string reference to 'UserFeed'
feeds_test_alter_source.services.yml in tests/modules/feeds_test_alter_source/feeds_test_alter_source.services.yml
tests/modules/feeds_test_alter_source/feeds_test_alter_source.services.yml
1 service uses UserFeed
feeds_test_alter_source.user_feed in tests/modules/feeds_test_alter_source/feeds_test_alter_source.services.yml
Drupal\feeds_test_alter_source\EventSubscriber\UserFeed

File

tests/modules/feeds_test_alter_source/src/EventSubscriber/UserFeed.php, line 12

Namespace

Drupal\feeds_test_alter_source\EventSubscriber
View source
class UserFeed implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      FeedsEvents::PARSE => [
        [
          'afterParse',
          FeedsEvents::AFTER,
        ],
      ],
    ];
  }

  /**
   * Acts on parser result.
   */
  public function afterParse(ParseEvent $event) {
    if ($event
      ->getFeed()
      ->getType()
      ->id() != 'user_import') {

      // Not interested in this feed. Abort.
      return;
    }

    /** @var \Drupal\feeds\Feeds\Item\ItemInterface $item */
    foreach ($event
      ->getParserResult() as $item) {

      // Convert roles value to multiple values.
      foreach ([
        'role_ids',
        'role_labels',
      ] as $source_name) {
        $data = $item
          ->get($source_name);
        if (!empty($data)) {
          $item
            ->set($source_name, explode('|', $data));
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserFeed::afterParse public function Acts on parser result.
UserFeed::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.