Skip to content
Snippets Groups Projects
Commit 688f773d authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2340471 by clemens.tolboom, dawehner: Fixed Rest export views preview...

Issue #2340471 by clemens.tolboom, dawehner: Fixed Rest export views preview should show some output instead of 500.
parent da1b6642
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,12 @@ public function render() {
$rows[] = $this->view->rowPlugin->render($row);
}
return $this->serializer->serialize($rows, $this->displayHandler->getContentType());
$content_type = $this->displayHandler->getContentType();
if (!empty($this->view->live_preview)) {
$content_type = $this->options['formats'] ? reset($this->options['formats']) : 'json';
}
return $this->serializer->serialize($rows, $content_type);
}
/**
......
......@@ -11,6 +11,7 @@
use Drupal\views\Views;
use Drupal\views\Tests\Plugin\PluginTestBase;
use Drupal\views\Tests\ViewTestData;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests the serializer style plugin.
......@@ -259,9 +260,17 @@ public function testFieldRawOutput() {
}
/**
* Tests the preview output for json output.
* Tests the live preview output for json output.
*/
public function testPreview() {
public function testLivePreview() {
// We set up a request so it looks like an request in the live preview.
$request = new Request();
$request->setFormat('drupal_ajax', 'application/vnd.drupal-ajax');
$request->headers->set('Accept', 'application/vnd.drupal-ajax');
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
$request_stack = \Drupal::service('request_stack');
$request_stack->push($request);
$view = Views::getView('test_serializer_display_entity');
$view->setDisplay('rest_export_1');
$this->executeView($view);
......@@ -276,7 +285,6 @@ public function testPreview() {
$expected = String::checkPlain($serializer->serialize($entities, 'json'));
$view->display_handler->setContentType('json');
$view->live_preview = TRUE;
$build = $view->preview();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment