diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php index 5ce4a52..ca58809 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php @@ -59,7 +59,7 @@ class RestExport extends PathPluginBase { * * @var string */ - protected $contentType; + protected $contentType = 'json'; /** * The mime type for the response. @@ -78,7 +78,13 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $negotiation = $container->get('content_negotiation'); $request = $container->get('request'); - $this->setContentType($negotiation->getContentType($request)); + $request_content_type = $negotiation->getContentType($request); + // Only determine the requested content type if it's not 'html'. The default + // 'json' content will be used else. + if ($request_content_type !== 'html') { + $this->setContentType($request_content_type); + } + $this->setMimeType($request->getMimeType($this->contentType)); } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php index 5349955..be59700 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php @@ -120,12 +120,16 @@ public function testSerializerResponses() { $actual_json = $this->drupalGet('test/serialize/entity', array(), array('Accept: application/json')); $this->assertResponse(200); - $this->assertIdentical($actual_json, $expected, 'The expected JSON output was found.'); $expected = $serializer->serialize($entities, 'hal_json'); $actual_json = $this->drupalGet('test/serialize/entity', array(), array('Accept: application/hal+json')); $this->assertIdentical($actual_json, $expected, 'The expected HAL output was found.'); + + // Test that the default output will be JSON if html is requested. + $expected = $serializer->serialize($entities, 'json'); + $actual = $this->drupalGet('test/serialize/entity'); + $this->assertIdentical($actual, $expected, 'If json module is enabled by default json output is returned.'); } /** @@ -237,9 +241,9 @@ public function testPreview() { $entities[] = $row->_entity; } - $expected = check_plain($serializer->serialize($entities, 'hal_json')); + $expected = check_plain($serializer->serialize($entities, 'json')); - $view->display_handler->setContentType('hal_json'); + $view->display_handler->setContentType('json'); $view->live_preview = TRUE; $build = $view->preview();