class SyndicationParser in Feeds 8.3
Defines an RSS and Atom feed parser.
Plugin annotation
@FeedsParser(
id = "syndication",
title = @Translation("RSS/Atom"),
description = @Translation("Default parser for RSS, Atom and RDF feeds.")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\feeds\Plugin\Type\PluginBase implements FeedsPluginInterface uses DependencyTrait
- class \Drupal\feeds\Feeds\Parser\SyndicationParser implements ParserInterface
- class \Drupal\feeds\Plugin\Type\PluginBase implements FeedsPluginInterface uses DependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SyndicationParser
1 file declares its use of SyndicationParser
- SyndicationParserTest.php in tests/
src/ Unit/ Feeds/ Parser/ SyndicationParserTest.php
File
- src/
Feeds/ Parser/ SyndicationParser.php, line 25
Namespace
Drupal\feeds\Feeds\ParserView source
class SyndicationParser extends PluginBase implements ParserInterface {
/**
* {@inheritdoc}
*/
public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result, StateInterface $state) {
$result = new ParserResult();
Reader::setExtensionManager(\Drupal::service('feed.bridge.reader'));
Reader::registerExtension('GeoRSS');
$raw = $fetcher_result
->getRaw();
if (!strlen(trim($raw))) {
throw new EmptyFeedException();
}
try {
$channel = Reader::importString($raw);
} catch (ExceptionInterface $e) {
$args = [
'%site' => $feed
->label(),
'%error' => trim($e
->getMessage()),
];
throw new \RuntimeException($this
->t('The feed from %site seems to be broken because of error "%error".', $args));
}
foreach ($channel as $delta => $entry) {
$item = new SyndicationItem();
// Move the values to an array as expected by processors.
$item
->set('title', $entry
->getTitle())
->set('guid', $entry
->getId())
->set('url', $entry
->getLink())
->set('guid', $entry
->getId())
->set('url', $entry
->getLink())
->set('description', $entry
->getDescription())
->set('content', $entry
->getContent())
->set('tags', $entry
->getCategories()
->getValues())
->set('feed_title', $channel
->getTitle())
->set('feed_description', $channel
->getDescription())
->set('feed_url', $channel
->getLink());
if ($image = $channel
->getImage()) {
$item
->set('feed_image_uri', $image['uri']);
}
if ($enclosure = $entry
->getEnclosure()) {
$item
->set('enclosures', [
rawurldecode($enclosure->url),
]);
}
if ($author = $entry
->getAuthor()) {
$author += [
'name' => '',
'email' => '',
];
$item
->set('author_name', $author['name'])
->set('author_email', $author['email']);
}
if ($date = $entry
->getDateCreated()) {
$item
->set('timestamp', $date
->getTimestamp());
}
if ($date = $entry
->getDateModified()) {
$item
->set('updated', $date
->getTimestamp());
}
if ($point = $entry
->getGeoPoint()) {
$item
->set('georss_lat', $point['lat'])
->set('georss_lon', $point['lon']);
}
$result
->addItem($item);
}
return $result;
}
/**
* {@inheritdoc}
*/
public function getMappingSources() {
return [
'feed_title' => [
'label' => $this
->t('Feed title'),
'description' => $this
->t('Title of the feed.'),
],
'feed_description' => [
'label' => $this
->t('Feed description'),
'description' => $this
->t('Description of the feed.'),
],
'feed_image_uri' => [
'label' => $this
->t('Feed image'),
'description' => $this
->t('The URL of the feed image.'),
],
'feed_url' => [
'label' => $this
->t('Feed URL (link)'),
'description' => $this
->t('URL of the feed.'),
],
'title' => [
'label' => $this
->t('Title'),
'description' => $this
->t('Title of the feed item.'),
'suggestions' => [
'targets' => [
'subject',
'title',
'label',
'name',
],
'types' => [
'field_item:text' => [],
],
],
],
'content' => [
'label' => $this
->t('Content'),
'description' => $this
->t('Content of the feed item.'),
'suggested' => [
'body',
],
'suggestions' => [
'targets' => [
'body',
],
'types' => [
'field_item:text_with_summary' => [],
],
],
],
'description' => [
'label' => $this
->t('Description'),
'description' => $this
->t('Description of the feed item.'),
'suggested' => [
'body',
],
'suggestions' => [
'targets' => [
'body',
],
'types' => [
'field_item:text_with_summary' => [],
],
],
],
'author_name' => [
'label' => $this
->t('Author name'),
'description' => $this
->t("Name of the feed item's author."),
'suggestions' => [
'types' => [
'entity_reference_field' => [
'target_type' => 'user',
],
],
],
],
'author_email' => [
'label' => $this
->t('Author email'),
'description' => $this
->t("Name of the feed item's email address."),
],
'timestamp' => [
'label' => $this
->t('Published date'),
'description' => $this
->t('Published date as UNIX time GMT of the feed item.'),
'suggestions' => [
'targets' => [
'created',
],
],
],
'updated' => [
'label' => $this
->t('Updated date'),
'description' => $this
->t('Updated date as UNIX time GMT of the feed item.'),
'suggestions' => [
'targets' => [
'changed',
],
],
],
'url' => [
'label' => $this
->t('Item URL (link)'),
'description' => $this
->t('URL of the feed item.'),
'suggestions' => [
'targets' => [
'url',
],
],
],
'guid' => [
'label' => $this
->t('Item GUID'),
'description' => $this
->t('Global Unique Identifier of the feed item.'),
'suggestions' => [
'targets' => [
'guid',
],
],
],
'tags' => [
'label' => $this
->t('Categories'),
'description' => $this
->t('An array of categories that have been assigned to the feed item.'),
'suggestions' => [
'targets' => [
'field_tags',
],
'types' => [
'field_item:taxonomy_term_reference' => [],
],
],
],
'georss_lat' => [
'label' => $this
->t('Item latitude'),
'description' => $this
->t('The feed item latitude.'),
],
'georss_lon' => [
'label' => $this
->t('Item longitude'),
'description' => $this
->t('The feed item longitude.'),
],
'enclosures' => [
'label' => $this
->t('Enclosures'),
'description' => $this
->t('A list of enclosures attached to the feed item.'),
'suggestions' => [
'types' => [
'field_item:file' => [],
],
],
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The importer this plugin is working for. | |
PluginBase:: |
protected | property | The link generator. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
protected | property | The url generator. | |
PluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
2 |
PluginBase:: |
private | function | Returns the service container. | |
PluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
7 |
PluginBase:: |
public | function |
Returns default feed configuration. Overrides FeedsPluginInterface:: |
3 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
PluginBase:: |
protected | function | Returns the link generator service. | |
PluginBase:: |
public | function | A feed is being deleted. | 3 |
PluginBase:: |
public | function | A feed is being saved. | |
PluginBase:: |
public | function | The feed type is being deleted. | 1 |
PluginBase:: |
public | function | The feed type is being saved. | 1 |
PluginBase:: |
public | function |
Returns the type of plugin. Overrides FeedsPluginInterface:: |
|
PluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
1 |
PluginBase:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
PluginBase:: |
protected | function | Returns the URL generator service. | |
PluginBase:: |
public | function |
Constructs a PluginBase object. Overrides PluginBase:: |
4 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
SyndicationParser:: |
public | function |
Declare the possible mapping sources that this parser produces. Overrides ParserInterface:: |
|
SyndicationParser:: |
public | function |
Parses content returned by fetcher. Overrides ParserInterface:: |