You are here

class CsvFeed in Feeds 8.3

Alters the parsed result for the feed type 'csv'.

Hierarchy

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

Expanded class hierarchy of CsvFeed

1 string reference to 'CsvFeed'
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 CsvFeed
feeds_test_alter_source.my_feed in tests/modules/feeds_test_alter_source/feeds_test_alter_source.services.yml
Drupal\feeds_test_alter_source\EventSubscriber\CsvFeed

File

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

Namespace

Drupal\feeds_test_alter_source\EventSubscriber
View source
class CsvFeed 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() != 'csv') {

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

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

      // Set title to lowercase.
      $item
        ->set('service_description', strtolower($item
        ->get('service_description')));

      // Keep only the first word of "à la carte".
      $carte = $item
        ->get('a_la_carte');
      $carte = strtok($carte, ' ');
      $carte = preg_replace('/[^a-zA-Z\\-]/', '', $carte);
      $item
        ->set('a_la_carte', $carte);
    }
  }

}

Members

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