public function JsonFeedSerializer::render in JSON Feed 8
Render the display in this style.
Overrides StylePluginBase::render
File
- src/
Plugin/ views/ style/ JsonFeedSerializer.php, line 163
Class
- JsonFeedSerializer
- Default style plugin to render a JSON feed.
Namespace
Drupal\json_feed\Plugin\views\styleCode
public function render() {
// Build items list.
$items = [];
foreach ($this->view->result as $row_index => $row) {
$this->view->row_index = $row_index;
$items[] = $this->view->rowPlugin
->render($row);
}
unset($this->view->row_index);
// Create feed.
$feed['version'] = 'https://jsonfeed.org/version/1';
$feed['title'] = strip_tags($this
->getTitle());
$feed['description'] = strip_tags($this
->getDescription());
$feed['home_page_url'] = strip_tags($this
->getFeedHomePageUrl());
$feed['feed_url'] = strip_tags($this->displayHandler
->getUrl()
->setAbsolute()
->toString());
$feed['favicon'] = strip_tags($this
->getFavicon());
$feed['author'] = array_map('strip_tags', $this
->getAuthor());
if ($next_url = $this
->getNextPage()) {
$feed['next_url'] = strip_tags($next_url);
}
$feed['items'] = $items;
// Remove empty attributes.
$feed = array_filter($feed);
// Add expired, which if false would be stripped out by array_filter.
$feed['expired'] = $this
->isFeedExpired();
return Json::encode($feed);
}