MyFeed.php in Feeds 8.3
File
tests/modules/feeds_test_extra_sources/src/EventSubscriber/MyFeed.php
View source
<?php
namespace Drupal\feeds_test_extra_sources\EventSubscriber;
use Drupal\feeds\Event\FeedsEvents;
use Drupal\feeds\Event\ParseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyFeed implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
FeedsEvents::PARSE => [
[
'afterParse',
FeedsEvents::AFTER,
],
],
];
}
public function afterParse(ParseEvent $event) {
if ($event
->getFeed()
->getType()
->id() != 'my_feed') {
return;
}
foreach ($event
->getParserResult() as $item) {
$title = $item
->get('title');
$slogan = $item
->get('site:slogan');
$item
->set('title', strtolower($title));
$word = strtok($title, ' ');
$word = preg_replace('/[^a-zA-Z\\-]/', '', $word);
$item
->set('site:slogan', str_replace('It', $word, $slogan));
}
}
}
Classes
Name |
Description |
MyFeed |
Alters the parsed result for the feed type 'my_feed'. |