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..a32e0e1 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,12 @@ 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 set the requested content type if it's not html. + 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..be89aa9 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php @@ -126,6 +126,11 @@ public function testSerializerResponses() { $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 by default the output will be JSON. + $expected = $serializer->serialize($entities, 'json'); + $actual_xml = $this->drupalGet('test/serialize/entity'); + $this->assertIdentical($actual_xml, $expected, 'By default json output is returned.'); } /**