diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index dd5ae28afd..a00dafdc12 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -9,6 +9,7 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\State\StateInterface; +use Drupal\rest\Plugin\views\style\Serializer; use Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface; use Drupal\views\Render\ViewsRenderPipelineMarkup; use Drupal\views\ViewExecutable; @@ -20,6 +21,9 @@ /** * The plugin that handles Data response callbacks for REST resources. * + * Style plugins that work with this class must extend + * \Drupal\rest\Plugin\views\style\Serializer. + * * @ingroup views_display_plugins * * @ViewsDisplay( @@ -30,6 +34,8 @@ * admin = @Translation("REST export"), * returns_response = TRUE * ) + * + * @see \Drupal\rest\Plugin\views\style\Serializer */ class RestExport extends PathPluginBase implements ResponseDisplayPluginInterface { @@ -328,9 +334,9 @@ public function collectRoutes(RouteCollection $collection) { if ($route = $collection->get("view.$view_id.$display_id")) { $style_plugin = $this->getPlugin('style'); - if (!method_exists($style_plugin, 'getFormats') || !method_exists($style_plugin, 'getFormatOptions')) { + if (!$style_plugin instanceof Serializer) { $class_name = get_class($style_plugin); - throw new \Exception("Views style plugins used with REST exports must provide methods getFormats and getFormatOptions. Plugin class {$class_name} doesn't provide these methods."); + throw new \Exception("Views style plugins used with REST exports must use be an instance of \\Drupal\\rest\\Plugin\\views\\style\\Serializer, {$class_name} found."); } // REST exports should only respond to GET methods. $route->setMethods(['GET']); diff --git a/core/modules/rest/src/Plugin/views/style/Serializer.php b/core/modules/rest/src/Plugin/views/style/Serializer.php index 51c126f6ab..c64c5a6a16 100644 --- a/core/modules/rest/src/Plugin/views/style/Serializer.php +++ b/core/modules/rest/src/Plugin/views/style/Serializer.php @@ -12,6 +12,9 @@ /** * The style plugin for serialized output formats. * + * Style plugins must extend this class to work with the + * \Drupal\rest\Plugin\views\display\RestExport display plugin. + * * @ingroup views_style_plugins * * @ViewsStyle( @@ -20,6 +23,8 @@ * help = @Translation("Serializes views row data using the Serializer component."), * display_types = {"data"} * ) + * + * @see \Drupal\rest\Plugin\views\display\RestExport */ class Serializer extends StylePluginBase implements CacheableDependencyInterface {