diff --git a/src/EventSubscriber/AfterParseBase.php b/src/EventSubscriber/AfterParseBase.php new file mode 100644 index 0000000..7459119 --- /dev/null +++ b/src/EventSubscriber/AfterParseBase.php @@ -0,0 +1,86 @@ +applies($event)) { + return; + } + + /** @var \Drupal\feeds\Result\ParserResultInterface */ + $result = $event->getParserResult(); + + for ($i = 0; $i < $result->count(); $i++) { + if (!$result->offsetExists($i)) { + break; + } + + /** @var \Drupal\feeds\Feeds\Item\ItemInterface */ + $item = $result->offsetGet($i); + + try { + $this->alterItem($item, $event); + } + catch (SkipItemException $e) { + $result->offsetUnset($i); + $i--; + } + } + } + + /** + * Returns if parsing should apply. + * + * @param \Drupal\feeds\Event\ParseEvent $event + * The parse event. + * + * @return bool + * True, if altering should continue. + * False otherwise. + */ + public function applies(ParseEvent $event) { + return TRUE; + } + + /** + * Alters a single item. + * + * @param \Drupal\feeds\Feeds\Item\ItemInterface + * The item to make modifications on. + * @param \Drupal\feeds\Event\ParseEvent $event + * The parse event. + * + * @throws \Drupal\Feeds\Exception\SkipItemException + * In case the item should not be imported. + */ + protected function alterItem(ItemInterface $item, ParseEvent $event) {} + +} \ No newline at end of file diff --git a/src/Exception/SkipItemException.php b/src/Exception/SkipItemException.php new file mode 100644 index 0000000..0cde4b0 --- /dev/null +++ b/src/Exception/SkipItemException.php @@ -0,0 +1,8 @@ +