public function FeedsSubscriber::afterParse in Feeds Tamper 8.2
Acts on parser result.
File
- src/
EventSubscriber/ FeedsSubscriber.php, line 51
Class
- FeedsSubscriber
- Subscriber to Feeds events.
Namespace
Drupal\feeds_tamper\EventSubscriberCode
public function afterParse(ParseEvent $event) {
/** @var \Drupal\feeds\FeedInterface $feed */
$feed = $event
->getFeed();
/** @var \Drupal\feeds_tamper\FeedTypeTamperMetaInterface $tamper_meta */
$tamper_meta = $this->tamperManager
->getTamperMeta($feed
->getType());
// Load the tamper plugins that need to be applied to Feeds.
$tampers_by_source = $tamper_meta
->getTampersGroupedBySource();
// Abort if there are no tampers to apply on the current feed.
if (empty($tampers_by_source)) {
return;
}
/** @var \Drupal\feeds\Result\ParserResultInterface $result */
$result = $event
->getParserResult();
for ($i = 0; $i < $result
->count(); $i++) {
if (!$result
->offsetExists($i)) {
break;
}
/** @var \Drupal\feeds\Feeds\Item\ItemInterface $item */
$item = $result
->offsetGet($i);
try {
$this
->alterItem($item, $event, $tampers_by_source);
} catch (SkipTamperItemException $e) {
$result
->offsetUnset($i);
$i--;
}
}
}