public function CsvFeed::afterParse in Feeds 8.3
Acts on parser result.
File
- tests/
modules/ feeds_test_alter_source/ src/ EventSubscriber/ CsvFeed.php, line 28
Class
- CsvFeed
- Alters the parsed result for the feed type 'csv'.
Namespace
Drupal\feeds_test_alter_source\EventSubscriberCode
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);
}
}