Commit 7ea1cd95 authored by alexpott's avatar alexpott

Issue #2221433 by damiankloip, dawehner: Clean up views rendering. Move stuff...

Issue #2221433 by damiankloip, dawehner: Clean up views rendering. Move stuff from template_preprocess_views_view(), into a #pre_render callback.
parent 577eab2e
...@@ -86,7 +86,7 @@ public function preRender(&$values) { ...@@ -86,7 +86,7 @@ public function preRender(&$values) {
public function render(ResultRow $values) { public function render(ResultRow $values) {
$links = array(); $links = array();
foreach ($this->options['fields'] as $field) { foreach ($this->options['fields'] as $field) {
$rendered_field = $this->view->style_plugin->getField($this->view->row_index, $field); $rendered_field = $this->view->style_plugin->getField($values->index, $field);
if (empty($rendered_field)) { if (empty($rendered_field)) {
continue; continue;
} }
......
...@@ -88,17 +88,14 @@ public function render() { ...@@ -88,17 +88,14 @@ public function render() {
// @todo We don't display grouping info for now. Could be useful for select // @todo We don't display grouping info for now. Could be useful for select
// widget, though. // widget, though.
$results = array(); $results = array();
$this->view->row_index = 0;
foreach ($sets as $records) { foreach ($sets as $records) {
foreach ($records as $values) { foreach ($records as $values) {
// Sanitize HTML, remove line breaks and extra whitespace. // Sanitize HTML, remove line breaks and extra whitespace.
$output = $this->view->rowPlugin->render($values); $output = $this->view->rowPlugin->render($values);
$output = drupal_render($output); $output = drupal_render($output);
$results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $output))); $results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $output)));
$this->view->row_index++;
} }
} }
unset($this->view->row_index);
return $results; return $results;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Views; use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -720,9 +721,15 @@ protected function renderItems($items) { ...@@ -720,9 +721,15 @@ protected function renderItems($items) {
} }
/** /**
* Return an array of items for the field. * Gets an array of items for the field.
*
* @param \Drupal\views\ResultRow $values
* The result row object containing the values.
*
* @return array
* An array of items for the field.
*/ */
public function getItems($values) { public function getItems(ResultRow $values) {
$original_entity = $this->getEntity($values); $original_entity = $this->getEntity($values);
if (!$original_entity) { if (!$original_entity) {
return array(); return array();
...@@ -739,7 +746,7 @@ public function getItems($values) { ...@@ -739,7 +746,7 @@ public function getItems($values) {
// Pass the View object in the display so that fields can act on it. // Pass the View object in the display so that fields can act on it.
'views_view' => $this->view, 'views_view' => $this->view,
'views_field' => $this, 'views_field' => $this,
'views_row_id' => $this->view->row_index, 'views_row_id' => $values->index,
); );
$render_array = $entity->get($this->definition['field_name'])->view($display); $render_array = $entity->get($this->definition['field_name'])->view($display);
......
...@@ -134,7 +134,7 @@ public function validateOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -134,7 +134,7 @@ public function validateOptionsForm(&$form, FormStateInterface $form_state) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function render(ResultRow $values) { public function render(ResultRow $values) {
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->'; return '<!--form-item-' . $this->options['id'] . '--' . $values->index . '-->';
} }
/** /**
......
...@@ -43,7 +43,6 @@ public function testRole() { ...@@ -43,7 +43,6 @@ public function testRole() {
$view = Views::getView('test_views_handler_field_role'); $view = Views::getView('test_views_handler_field_role');
$this->executeView($view); $this->executeView($view);
$view->row_index = 0;
// The role field is populated during preRender. // The role field is populated during preRender.
$view->field['rid']->preRender($view->result); $view->field['rid']->preRender($view->result);
$render = $view->field['rid']->advancedRender($view->result[0]); $render = $view->field['rid']->advancedRender($view->result[0]);
......
...@@ -30,8 +30,6 @@ public function testUserName() { ...@@ -30,8 +30,6 @@ public function testUserName() {
$view = Views::getView('test_views_handler_field_user_name'); $view = Views::getView('test_views_handler_field_user_name');
$this->executeView($view); $this->executeView($view);
$view->row_index = 0;
$view->field['name']->options['link_to_user'] = TRUE; $view->field['name']->options['link_to_user'] = TRUE;
$username = $view->result[0]->users_field_data_name = $this->randomMachineName(); $username = $view->result[0]->users_field_data_name = $this->randomMachineName();
$view->result[0]->users_field_data_uid = 1; $view->result[0]->users_field_data_uid = 1;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
namespace Drupal\views\Form; namespace Drupal\views\Form;
use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
...@@ -68,7 +67,7 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface { ...@@ -68,7 +67,7 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface {
/** /**
* Constructs a ViewsForm object. * Constructs a ViewsForm object.
* *
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $controller_resolver * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver to get the subform form objects. * The class resolver to get the subform form objects.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator to generate the form action. * The url generator to generate the form action.
...@@ -79,8 +78,8 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface { ...@@ -79,8 +78,8 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface {
* @param string $view_display_id * @param string $view_display_id
* The ID of the active view's display. * The ID of the active view's display.
*/ */
public function __construct(ClassResolverInterface $controller_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, $view_id, $view_display_id) { public function __construct(ClassResolverInterface $class_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, $view_id, $view_display_id) {
$this->classResolver = $controller_resolver; $this->classResolver = $class_resolver;
$this->urlGenerator = $url_generator; $this->urlGenerator = $url_generator;
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->viewId = $view_id; $this->viewId = $view_id;
...@@ -92,7 +91,7 @@ public function __construct(ClassResolverInterface $controller_resolver, UrlGene ...@@ -92,7 +91,7 @@ public function __construct(ClassResolverInterface $controller_resolver, UrlGene
*/ */
public static function create(ContainerInterface $container, $view_id = NULL, $view_display_id = NULL) { public static function create(ContainerInterface $container, $view_id = NULL, $view_display_id = NULL) {
return new static( return new static(
$container->get('controller_resolver'), $container->get('class_resolver'),
$container->get('url_generator'), $container->get('url_generator'),
$container->get('request_stack'), $container->get('request_stack'),
$view_id, $view_id,
...@@ -116,7 +115,7 @@ public function getFormID() { ...@@ -116,7 +115,7 @@ public function getFormID() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = NULL) { public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = []) {
$form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 'views_form_views_form'; $form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 'views_form_views_form';
$form_state['step_controller']['views_form_views_form'] = 'Drupal\views\Form\ViewsFormMainForm'; $form_state['step_controller']['views_form_views_form'] = 'Drupal\views\Form\ViewsFormMainForm';
......
...@@ -22,7 +22,7 @@ public function getFormID() { ...@@ -22,7 +22,7 @@ public function getFormID() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = NULL) { public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = []) {
$form['#prefix'] = '<div class="views-form">'; $form['#prefix'] = '<div class="views-form">';
$form['#suffix'] = '</div>'; $form['#suffix'] = '</div>';
$form['#theme'] = 'form'; $form['#theme'] = 'form';
...@@ -30,12 +30,10 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu ...@@ -30,12 +30,10 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu
// Add the output markup to the form array so that it's included when the form // Add the output markup to the form array so that it's included when the form
// array is passed to the theme function. // array is passed to the theme function.
$form['output'] = array( $form['output'] = $output;
'#markup' => $output, // This way any additional form elements will go before the view
// This way any additional form elements will go before the view // (below the exposed widgets).
// (below the exposed widgets). $form['output']['#weight'] = 50;
'#weight' => 50,
);
$form['actions'] = array( $form['actions'] = array(
'#type' => 'actions', '#type' => 'actions',
......
...@@ -142,8 +142,8 @@ public function cacheSet($type) { ...@@ -142,8 +142,8 @@ public function cacheSet($type) {
\Drupal::cache($this->resultsBin)->set($this->generateResultsKey(), $data, $this->cacheSetExpire($type), $this->getCacheTags()); \Drupal::cache($this->resultsBin)->set($this->generateResultsKey(), $data, $this->cacheSetExpire($type), $this->getCacheTags());
break; break;
case 'output': case 'output':
$this->storage['output'] = $this->view->display_handler->output; $this->gatherHeaders($this->view->display_handler->output);
$this->gatherHeaders(); $this->storage['output'] = drupal_render($this->view->display_handler->output, TRUE);
\Drupal::cache($this->outputBin)->set($this->generateOutputKey(), $this->storage, $this->cacheSetExpire($type), $this->getCacheTags()); \Drupal::cache($this->outputBin)->set($this->generateOutputKey(), $this->storage, $this->cacheSetExpire($type), $this->getCacheTags());
break; break;
} }
...@@ -177,8 +177,13 @@ public function cacheGet($type) { ...@@ -177,8 +177,13 @@ public function cacheGet($type) {
if ($cache = \Drupal::cache($this->outputBin)->get($this->generateOutputKey())) { if ($cache = \Drupal::cache($this->outputBin)->get($this->generateOutputKey())) {
if (!$cutoff || $cache->created > $cutoff) { if (!$cutoff || $cache->created > $cutoff) {
$this->storage = $cache->data; $this->storage = $cache->data;
$this->view->display_handler->output = $cache->data['output'];
$this->restoreHeaders(); $this->restoreHeaders();
$this->view->display_handler->output = array(
'#attached' => &$this->view->element['#attached'],
'#markup' => $cache->data['output'],
);
return TRUE; return TRUE;
} }
} }
...@@ -233,9 +238,12 @@ public function cacheStart() { ...@@ -233,9 +238,12 @@ public function cacheStart() {
} }
/** /**
* Gather the JS/CSS from the render array, the html head from the band data. * Gather the JS/CSS from the render array and the html head from band data.
*
* @param array $render_array
* The view render array to collect data from.
*/ */
protected function gatherHeaders() { protected function gatherHeaders(array $render_array = []) {
// Simple replacement for head // Simple replacement for head
if (isset($this->storage['head'])) { if (isset($this->storage['head'])) {
$this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head()); $this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head());
...@@ -244,9 +252,8 @@ protected function gatherHeaders() { ...@@ -244,9 +252,8 @@ protected function gatherHeaders() {
$this->storage['head'] = ''; $this->storage['head'] = '';
} }
$attached = $this->storage['output']['#attached']; $this->storage['css'] = $render_array['#attached']['css'];
$this->storage['css'] = $attached['css']; $this->storage['js'] = $render_array['#attached']['js'];
$this->storage['js'] = $attached['js'];
} }
/** /**
......
...@@ -232,9 +232,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -232,9 +232,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
} }
/** /**
* Attach to another view. * {@inheritdoc}
*/ */
public function attachTo(ViewExecutable $view, $display_id) { public function attachTo(ViewExecutable $view, $display_id, array &$build) {
$displays = $this->getOption('displays'); $displays = $this->getOption('displays');
if (empty($displays[$display_id])) { if (empty($displays[$display_id])) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Theme\Registry; use Drupal\Core\Theme\Registry;
use Drupal\views\Form\ViewsForm;
use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\Plugin\views\area\AreaPluginBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\PluginBase;
...@@ -419,8 +420,15 @@ public function usesAreas() { ...@@ -419,8 +420,15 @@ public function usesAreas() {
/** /**
* Allow displays to attach to other views. * Allow displays to attach to other views.
*
* @param \Drupal\views\ViewExecutable $view
* The views executable.
* @param string $display_id
* The display to attach to.
* @param array $build
* The parent view render array.
*/ */
public function attachTo(ViewExecutable $view, $display_id) { } public function attachTo(ViewExecutable $view, $display_id, array &$build) { }
/** /**
* Static member function to list which sections are defaultable * Static member function to list which sections are defaultable
...@@ -2125,11 +2133,86 @@ public function getMenuLinks() { ...@@ -2125,11 +2133,86 @@ public function getMenuLinks() {
* Render this display. * Render this display.
*/ */
public function render() { public function render() {
$rows = (!empty($this->view->result) || $this->view->style_plugin->evenEmpty()) ? $this->view->style_plugin->render($this->view->result) : array();
$element = array( $element = array(
'#theme' => $this->themeFunctions(), '#theme' => $this->themeFunctions(),
'#view' => $this->view, '#view' => $this->view,
// Assigned by reference so anything added in $element['#attached'] will
// be available on the view.
'#attached' => &$this->view->element['#attached'],
'#pre_render' => [[$this, 'elementPreRender']],
'#rows' => $rows,
); );
$element['#attached'] = &$this->view->element['#attached'];
return $element;
}
/**
* #pre_render callback for view display rendering.
*
* @see self::render()
*
* @param array $element
* The element to #pre_render
*
* @return array
* The processed element.
*/
public function elementPreRender(array $element) {
$view = $element['#view'];
$empty = empty($view->result);
// Force a render array so CSS/JS can be attached.
if (!is_array($element['#rows'])) {
$element['#rows'] = array('#markup' => $element['#rows']);
}
$element['#header'] = $view->display_handler->renderArea('header', $empty);
$element['#footer'] = $view->display_handler->renderArea('footer', $empty);
$element['#empty'] = $empty ? $view->display_handler->renderArea('empty', $empty) : array();
$element['#exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : array();
$element['#more'] = $view->display_handler->renderMoreLink();
$element['#feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : array();
if ($view->display_handler->renderPager()) {
$exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL;
$element['#pager'] = $view->renderPager($exposed_input);
}
if (!empty($view->attachment_before)) {
$element['#attachment_before'] = $view->attachment_before;
}
if (!empty($view->attachment_after)) {
$element['#attachment_after'] = $view->attachment_after;
}
// If form fields were found in the view, reformat the view output as a form.
if ($view->hasFormElements()) {
// Only render row output if there are rows. Otherwise, render the empty
// region.
if (!empty($element['#rows'])) {
$output = $element['#rows'];
}
else {
$output = $element['#empty'];
}
$form_object = ViewsForm::create(\Drupal::getContainer(), $view->storage->id(), $view->current_display);
$form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
// The form is requesting that all non-essential views elements be hidden,
// usually because the rendered step is not a view result.
if ($form['show_view_elements']['#value'] == FALSE) {
$element['#header'] = array();
$element['#exposed'] = array();
$element['#pager'] = array();
$element['#footer'] = array();
$element['#more'] = array();
$element['#feed_icon'] = array();
}
$element['#rows'] = $form;
}
return $element; return $element;
} }
......
...@@ -80,7 +80,7 @@ public function execute() { ...@@ -80,7 +80,7 @@ public function execute() {
$response = $this->view->getResponse(); $response = $this->view->getResponse();
$response->setContent($output); $response->setContent(drupal_render($output));
return $response; return $response;
} }
...@@ -94,7 +94,7 @@ public function preview() { ...@@ -94,7 +94,7 @@ public function preview() {
if (!empty($this->view->live_preview)) { if (!empty($this->view->live_preview)) {
$output = array( $output = array(
'#prefix' => '<pre>', '#prefix' => '<pre>',
'#markup' => String::checkPlain($output), '#markup' => String::checkPlain(drupal_render($output)),
'#suffix' => '</pre>', '#suffix' => '</pre>',
); );
} }
...@@ -253,9 +253,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { ...@@ -253,9 +253,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
} }
/** /**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::attachTo(). * {@inheritdoc}
*/ */
public function attachTo(ViewExecutable $clone, $display_id) { public function attachTo(ViewExecutable $clone, $display_id, array &$build) {
$displays = $this->getOption('displays'); $displays = $this->getOption('displays');
if (empty($displays[$display_id])) { if (empty($displays[$display_id])) {
return; return;
...@@ -266,7 +266,7 @@ public function attachTo(ViewExecutable $clone, $display_id) { ...@@ -266,7 +266,7 @@ public function attachTo(ViewExecutable $clone, $display_id) {
$clone->setDisplay($this->display['id']); $clone->setDisplay($this->display['id']);
$clone->buildTitle(); $clone->buildTitle();
if ($plugin = $clone->display_handler->getPlugin('style')) { if ($plugin = $clone->display_handler->getPlugin('style')) {
$plugin->attachTo($display_id, $this->getPath(), $clone->getTitle()); $plugin->attachTo($build, $display_id, $this->getPath(), $clone->getTitle());
} }
// Clean up. // Clean up.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\views\Plugin\views\join\JoinPluginBase; use Drupal\views\Plugin\views\join\JoinPluginBase;
use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\HandlerBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Views; use Drupal\views\Views;
...@@ -1428,7 +1429,12 @@ function execute(ViewExecutable $view) { ...@@ -1428,7 +1429,12 @@ function execute(ViewExecutable $view) {
$result = $query->execute(); $result = $query->execute();
$result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow'); $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow');
// Setup the result row objects.
$view->result = iterator_to_array($result); $view->result = iterator_to_array($result);
array_walk($view->result, function(ResultRow $row, $index) {
$row->index = $index;
});
$view->pager->postExecute($view->result); $view->pager->postExecute($view->result);
$view->pager->updatePageInfo(); $view->pager->updatePageInfo();
......
...@@ -32,7 +32,7 @@ class Opml extends StylePluginBase { ...@@ -32,7 +32,7 @@ class Opml extends StylePluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function attachTo($display_id, $path, $title) { public function attachTo(array &$build, $display_id, $path, $title) {
$display = $this->view->displayHandlers->get($display_id); $display = $this->view->displayHandlers->get($display_id);
$url_options = array(); $url_options = array();
$input = $this->view->getExposedInput(); $input = $this->view->getExposedInput();
...@@ -45,19 +45,15 @@ public function attachTo($display_id, $path, $title) { ...@@ -45,19 +45,15 @@ public function attachTo($display_id, $path, $title) {
if ($display->hasPath()) { if ($display->hasPath()) {
if (empty($this->preview)) { if (empty($this->preview)) {
$build['#attached']['drupal_add_feed'][] = array($url, $title); $build['#attached']['drupal_add_feed'][] = array($url, $title);
drupal_render($build);
} }
} }
else { else {
if (empty($this->view->feed_icon)) {
$this->view->feed_icon = '';
}
$feed_icon = array( $feed_icon = array(
'#theme' => 'feed_icon', '#theme' => 'feed_icon',
'#url' => $url, '#url' => $url,
'#title' => $title, '#title' => $title,
); );
$this->view->feed_icon .= drupal_render($feed_icon); $this->view->feed_icon = $feed_icon;
} }
} }
...@@ -83,7 +79,7 @@ public function render() { ...@@ -83,7 +79,7 @@ public function render() {
'#rows' => $rows, '#rows' => $rows,
); );
unset($this->view->row_index); unset($this->view->row_index);
return drupal_render($build); return $build;
} }
} }
...@@ -32,7 +32,7 @@ class Rss extends StylePluginBase { ...@@ -32,7 +32,7 @@ class Rss extends StylePluginBase {
*/ */
protected $usesRowPlugin = TRUE; protected $usesRowPlugin = TRUE;
public function attachTo($display_id, $path, $title) { public function attachTo(array &$build, $display_id, $path, $title) {
$display = $this->view->displayHandlers->get($display_id); $display = $this->view->displayHandlers->get($display_id);
$url_options = array(); $url_options = array();
$input = $this->view->getExposedInput(); $input = $this->view->getExposedInput();
...@@ -44,27 +44,25 @@ public function attachTo($display_id, $path, $title) { ...@@ -44,27 +44,25 @@ public function attachTo($display_id, $path, $title) {
$url = url($this->view->getUrl(NULL, $path), $url_options); $url = url($this->view->getUrl(NULL, $path), $url_options);
if ($display->hasPath()) { if ($display->hasPath()) {
if (empty($this->preview)) { if (empty($this->preview)) {
// Add a call for drupal_add_feed to the view attached data.
$build['#attached']['drupal_add_feed'][] = array($url, $title); $build['#attached']['drupal_add_feed'][] = array($url, $title);
drupal_process_attached($build);
} }
} }
else { else {
if (empty($this->view->feed_icon)) {
$this->view->feed_icon = '';
}
$feed_icon = array( $feed_icon = array(
'#theme' => 'feed_icon', '#theme' => 'feed_icon',
'#url' => $url, '#url' => $url,
'#title' => $title, '#title' => $title,
); );
$feed_icon['#attached']['drupal_add_html_head_link'][][] = array( $this->view->feed_icon = $feed_icon;
// Add a call for drupal_add_html_head_link to the view attached data.
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'alternate', 'rel' => 'alternate',
'type' => 'application/rss+xml', 'type' => 'application/rss+xml',
'title' => $title, 'title' => $title,
'href' => $url, 'href' => $url,
); );
$this->view->feed_icon .= drupal_render($feed_icon);
drupal_process_attached($feed_icon);
} }
} }
...@@ -116,7 +114,7 @@ public function getDescription() { ...@@ -116,7 +114,7 @@ public function getDescription() {
public function render() { public function render() {
if (empty($this->view->rowPlugin)) { if (empty($this->view->rowPlugin)) {
debug('Drupal\views\Plugin\views\style\Rss: Missing row plugin'); debug('Drupal\views\Plugin\views\style\Rss: Missing row plugin');
return; return array();
} }
$rows = ''; $rows = '';
...@@ -145,7 +143,7 @@ public function render() { ...@@ -145,7 +143,7 @@ public function render() {
'#rows' => SafeMarkup::set($rows), '#rows' => SafeMarkup::set($rows),
); );
unset($this->view->row_index); unset($this->view->row_index);