public function ParserBase::parse in Feeds extensible parsers 8
Parses content returned by fetcher.
@todo This needs more documentation.
Parameters
\Drupal\feeds\FeedInterface $feed: The feed we are parsing for.
\Drupal\feeds\Result\FetcherResultInterface $fetcher_result: The result returned by the fetcher.
\Drupal\feeds\StateInterface $state: The state object.
Return value
\Drupal\feeds\Result\ParserResultInterface The parser result object.
Overrides ParserInterface::parse
File
- src/
Feeds/ Parser/ ParserBase.php, line 247
Class
- ParserBase
- The Feeds extensible parser.
Namespace
Drupal\feeds_ex\Feeds\ParserCode
public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result, StateInterface $state) {
$this
->loadLibrary();
$this
->startErrorHandling();
$result = new ParserResult();
// @todo Set link?
// $fetcher_config = $feed->getConfigurationFor($feed->importer->fetcher);
// $result->link = is_string($fetcher_config['source']) ? $fetcher_config['source'] : '';
try {
$this
->setUp($feed, $fetcher_result, $state);
$this
->parseItems($feed, $fetcher_result, $result, $state);
$this
->cleanUp($feed, $result, $state);
} catch (EmptyFeedException $e) {
// The feed is empty.
$this
->getMessenger()
->addMessage($this
->t('The feed is empty.'), 'warning', FALSE);
} catch (Exception $exception) {
// Do nothing. Store for later.
}
// Display errors.
$errors = $this
->getErrors();
$this
->printErrors($errors, $this->configuration['display_errors'] ? RfcLogLevel::DEBUG : RfcLogLevel::ERROR);
$this
->stopErrorHandling();
if (isset($exception)) {
throw $exception;
}
return $result;
}