diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index b251a440d1..4e79194ebb 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -141,6 +141,8 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $request_content_type = $this->view->getRequest()->getRequestFormat(); + // This allows still falling back to the default for things like views + // preview. if ($request_content_type !== 'html') { $this->setContentType($request_content_type); $this->setMimeType($this->view->getRequest()->getMimeType($request_content_type)); @@ -321,10 +323,17 @@ public function collectRoutes(RouteCollection $collection) { // REST exports should only respond to GET methods. $route->setMethods(['GET']); - // Format as a string using pipes as a delimiter. - if ($formats = $style_plugin->getFormats()) { - $route->setRequirement('_format', implode('|', $formats)); + $formats = $style_plugin->getFormats(); + + // If there are no configured formats, add all formats that the serializer + // style plugin supports. + if (!$formats) { + $formats = $style_plugin->getFormatOptions(); } + + // Format as a string using pipes as a delimiter. + $route->setRequirement('_format', implode('|', $formats)); + // Add authentication to the route if it was set. If no authentication was // set, the default authentication will be used, which is cookie based by // default. diff --git a/core/modules/rest/src/Plugin/views/style/Serializer.php b/core/modules/rest/src/Plugin/views/style/Serializer.php index 7e9b4331ef..c58ec32419 100644 --- a/core/modules/rest/src/Plugin/views/style/Serializer.php +++ b/core/modules/rest/src/Plugin/views/style/Serializer.php @@ -197,7 +197,7 @@ public function calculateDependencies() { * @return string[] * An array of format options. Both key and value are the same. */ - protected function getFormatOptions() { + public function getFormatOptions() { $formats = array_keys($this->formatProviders); return array_combine($formats, $formats); }