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 a32e0e1..1e816e2 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 @@ -80,7 +80,12 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $request_content_type = $negotiation->getContentType($request); // Only set the requested content type if it's not html. - if ($request_content_type !== 'html') { + if ($request_content_type === 'html') { + if (\Drupal::moduleHandler()->moduleExists('hal_json')) { + $this->setContentType('hal_json'); + } + } + else { $this->setContentType($request_content_type); } 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 be89aa9..260361d 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php @@ -127,7 +127,12 @@ public function testSerializerResponses() { $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. + // Test that by default the output will be JSON if hal is enabled. + $expected = $serializer->serialize($entities, 'hal_json'); + $actual_xml = $this->drupalGet('test/serialize/entity'); + $this->assertIdentical($actual_xml, $expected, 'If hal modul is enabled by default hal_json output is returned.'); + + module_disable('hal'); $expected = $serializer->serialize($entities, 'json'); $actual_xml = $this->drupalGet('test/serialize/entity'); $this->assertIdentical($actual_xml, $expected, 'By default json output is returned.');