Skip to content
Snippets Groups Projects
Commit 962a6043 authored by Youri van Koppen's avatar Youri van Koppen
Browse files

Issue #3519989 by megachriz, irinaz: Added mapping source 'authors' to the...

Issue #3519989 by megachriz, irinaz: Added mapping source 'authors' to the RSS/Atom parser in order to use multiple values from <dc:creator>.
parent ea64d3b8
No related branches found
No related tags found
1 merge request!211Resolve #3519989 "Rss multiple authors"
Pipeline #496695 passed with warnings
......@@ -86,6 +86,7 @@ Pugsley
qaeda
Quxawitz
refetched
rosje
sanitizations
servicemanager
Skeletor
......
......
......@@ -49,6 +49,13 @@ class SyndicationItem extends BaseItem {
*/
protected $author_email;
/**
* An array of authors of the feed item.
*
* @var array
*/
protected $authors;
/**
* Published date as UNIX time GMT.
*
......
......
......@@ -123,6 +123,15 @@ class SyndicationParser extends ParserBase implements ParserInterface, Container
$item->set('author_name', $author['name'])
->set('author_email', $author['email']);
}
if ($authors = $entry->getAuthors()) {
$author_names = [];
foreach ($authors as $author) {
if (isset($author['name'])) {
$author_names[] = $author['name'];
}
}
$item->set('authors', $author_names);
}
if ($date = $entry->getDateCreated()) {
$item->set('timestamp', $date->getTimestamp());
}
......@@ -208,6 +217,13 @@ class SyndicationParser extends ParserBase implements ParserInterface, Container
'label' => $this->t('Author email'),
'description' => $this->t("Mail address of the feed item's author."),
],
'authors' => [
'label' => $this->t('Authors'),
'description' => $this->t('An array of authors of the feed item.'),
'suggestions' => [
'types' => ['field_item:text' => []],
],
],
'timestamp' => [
'label' => $this->t('Published date'),
'description' => $this->t('Published date as UNIX time GMT of the feed item.'),
......
......
<?xml version="1.0" encoding="utf-8" ?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>RSS Feed with Dublin Core namespace</title>
<link>https://www.example.com</link>
<description>RSS feed that makes use of the dc namespace</description>
<language>en</language>
<item>
<title>A lovely evening in ChrisBurg</title>
<link>https://www.example.com/lovely-evening-123</link>
<description>Chris and Rosje are going for a walk in the park and make a short stop in the center of the park, at the fountain.</description>
<guid isPermaLink="true">cdk:123</guid>
<pubDate>Do, 8 May 2025 20:32:00 +0100</pubDate>
<dc:creator>Chris the Koala</dc:creator>
<dc:creator>Rosje</dc:creator>
<dc:date>2025-05-08</dc:date>
<dc:source>The CdK newspaper</dc:source>
<dc:title>A very lovely evening in ChrisBurg</dc:title>
<dc:identifier>pmid:123</dc:identifier>
<dc:identifier>cdk/lovely-evening-123</dc:identifier>
</item>
</channel>
</rss>
......@@ -103,13 +103,30 @@ class SyndicationParserTest extends FeedsUnitTestCase {
$fetcher_result = new RawFetcherResult(file_get_contents($file), $this->getMockFileSystem());
$result = $this->parser->parse($this->feed, $fetcher_result, $this->state);
$this->assertSame(count($result), 6);
$this->assertSame($result[0]->get('title'), "First thoughts: Dems' Black Tuesday - msnbc.com");
$this->assertSame($result[0]->get('author_name'), 'Person Name');
$this->assertSame($result[0]->get('timestamp'), 1262805987);
$this->assertSame($result[0]->get('updated'), 1262805987);
$this->assertSame($result[0]->get('guid'), 'tag:news.google.com,2005:cluster=17593687403189');
$this->assertSame($result[3]->get('title'), 'NEWSMAKER-New Japan finance minister a fiery battler - Reuters');
$this->assertCount(6, $result);
$this->assertSame("First thoughts: Dems' Black Tuesday - msnbc.com", $result[0]->get('title'));
$this->assertSame('Person Name', $result[0]->get('author_name'));
$this->assertSame(['Person Name'], $result[0]->get('authors'));
$this->assertSame(1262805987, $result[0]->get('timestamp'));
$this->assertSame(1262805987, $result[0]->get('updated'));
$this->assertSame('tag:news.google.com,2005:cluster=17593687403189', $result[0]->get('guid'));
$this->assertSame('NEWSMAKER-New Japan finance minister a fiery battler - Reuters', $result[3]->get('title'));
}
/**
* Tests parsing a RSS feed using the Dublin Core namespace.
*
* @covers ::parse
*/
public function testParseDublinCoreFeed() {
$file = $this->resourcesPath() . '/rss/dublin-core.rss2';
$fetcher_result = new RawFetcherResult(file_get_contents($file), $this->getMockFileSystem());
$result = $this->parser->parse($this->feed, $fetcher_result, $this->state);
$this->assertCount(1, $result);
$this->assertSame('A lovely evening in ChrisBurg', $result[0]->get('title'));
$this->assertSame('Chris the Koala', $result[0]->get('author_name'));
$this->assertSame(['Chris the Koala', 'Rosje'], $result[0]->get('authors'));
}
/**
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment