Commit f5fd5a4d authored by dawehner's avatar dawehner Committed by tim.plunkett
Browse files

Issue #1637518 by dawehner: Fixed the todo in views_plugin_display_feed() and...

Issue #1637518 by dawehner: Fixed the todo in views_plugin_display_feed() and use a views-global response object.
parent c6cb3dec
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* Provides the view object type and associated methods. * Provides the view object type and associated methods.
*/ */
use Symfony\Component\HttpFoundation\Response;
/** /**
* @defgroup views_objects Objects that represent a View or part of a view * @defgroup views_objects Objects that represent a View or part of a view
* @{ * @{
...@@ -247,6 +249,13 @@ class view extends views_db_object { ...@@ -247,6 +249,13 @@ class view extends views_db_object {
*/ */
var $empty; var $empty;
/**
* Stores the current response object.
*
* @var Symfony\Component\HttpFoundation\Response
*/
protected $response = NULL;
/** /**
* Constructor * Constructor
*/ */
...@@ -1170,6 +1179,9 @@ function render($display_id = NULL) { ...@@ -1170,6 +1179,9 @@ function render($display_id = NULL) {
drupal_theme_initialize(); drupal_theme_initialize();
$config = config('views.settings'); $config = config('views.settings');
// Set the response so other parts can alter it.
$this->response = new Response('', 200);
$start = microtime(TRUE); $start = microtime(TRUE);
if (!empty($this->live_preview) && $config->get('views_show_additional_queries')) { if (!empty($this->live_preview) && $config->get('views_show_additional_queries')) {
$this->start_query_capture(); $this->start_query_capture();
...@@ -1476,6 +1488,29 @@ function access($displays = NULL, $account = NULL) { ...@@ -1476,6 +1488,29 @@ function access($displays = NULL, $account = NULL) {
return FALSE; return FALSE;
} }
/**
* Sets the used response object of the view.
*
* @param Symfony\Component\HttpFoundation\Response $response
* The response object which should be set.
*/
public function setResponse(Response $response) {
$this->response = $response;
}
/**
* Gets the response object used by the view.
*
* @return Symfony\Component\HttpFoundation\Response
* The response object of the view.
*/
public function getResponse() {
if (!isset($this->response)) {
$this->response = new Response();
}
return $this->response;
}
/** /**
* Get the view's current title. This can change depending upon how it * Get the view's current title. This can change depending upon how it
* was built. * was built.
......
...@@ -41,10 +41,10 @@ function execute() { ...@@ -41,10 +41,10 @@ function execute() {
if (empty($output)) { if (empty($output)) {
return drupal_not_found(); return drupal_not_found();
} }
// @todo: This is not a valid fix, because only the style plugin knows the
// Content-Type. There needs some global response object on the view which $response = $this->view->getResponse();
// can be manipulated and then is used optionally. $response->setContent($output);
return new Response($output, 200, array('Content-Type' => 'application/rss+xml; charset=utf-8')); return $response;
} }
function preview() { function preview() {
......
...@@ -895,7 +895,7 @@ function template_preprocess_views_view_rss(&$vars) { ...@@ -895,7 +895,7 @@ function template_preprocess_views_view_rss(&$vars) {
// During live preview we don't want to output the header since the contents // During live preview we don't want to output the header since the contents
// of the feed are being displayed inside a normal HTML page. // of the feed are being displayed inside a normal HTML page.
if (empty($vars['view']->live_preview)) { if (empty($vars['view']->live_preview)) {
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8'); $vars['view']->getResponse()->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment