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 47b3961..bec2bd1 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 @@ -60,7 +60,7 @@ class RestExport extends PathPluginBase { * * @var string */ - protected $contentType = NULL; + protected $contentType; /** * The mime type for the response. @@ -70,7 +70,7 @@ class RestExport extends PathPluginBase { protected $mimeType; /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::initDisplay(). + * {@inheritdoc} */ public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) { parent::initDisplay($view, $display, $options); @@ -84,21 +84,21 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType(). + * {@inheritdoc} */ protected function getType() { return 'data'; } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::usesExposed(). + * {@inheritdoc} */ public function usesExposed() { return FALSE; } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::displaysExposed(). + * {@inheritdoc} */ public function displaysExposed() { return FALSE; @@ -117,7 +117,7 @@ public function setMimeType($mime_type) { /** * Gets the mime type. * - * This will return any overriden mime type, otherwise returns the mime type + * This will return any overridden mime type, otherwise returns the mime type * from the request. * * @return string @@ -148,7 +148,7 @@ public function getContentType() { } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::defineOptions(). + * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); @@ -168,7 +168,7 @@ protected function defineOptions() { } /** - * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::optionsSummary(). + * {@inheritdoc} */ public function optionsSummary(&$categories, &$options) { parent::optionsSummary($categories, $options); @@ -205,17 +205,8 @@ public function collectRoutes(RouteCollection $collection) { // REST exports should only respond to get methods. $requirements = array('_method' => 'GET'); - // Only add requirements on formats if some have been configured, otherwise - // use all available formats. - if (!empty($style_plugin->options['formats'])) { - $formats = $style_plugin->options['formats']; - } - else { - $formats = $style_plugin->getFormats(); - } - // Format as a string using pipes as a delimeter. - $requirements['_format'] = implode('|', $formats); + $requirements['_format'] = implode('|', $style_plugin->getFormats()); // Add the new requirements to each route. foreach ($collection as $route) { @@ -224,7 +215,7 @@ public function collectRoutes(RouteCollection $collection) { } /** - * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::execute(). + * {@inheritdoc} */ public function execute() { parent::execute(); @@ -234,7 +225,7 @@ public function execute() { } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::render(). + * {@inheritdoc} */ public function render() { $build = array(); @@ -251,7 +242,7 @@ public function render() { } /** - * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::preview(). + * {@inheritdoc} * * The DisplayPluginBase preview method assumes we will be returning a render * array. The data plugin will already return the serialized string. diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php index e1c45cd..7ad22ba 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php @@ -12,6 +12,8 @@ use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Serializer\SerializerInterface; /** * The style plugin for serialized output formats. @@ -50,18 +52,30 @@ class Serializer extends StylePluginBase { * * @var array */ - protected $formats; + protected $formats = array(); /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::init(). + * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { - parent::init($view, $display, $options); + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('serializer'), + $container->getParameter('serializer.formats') + ); + } + + /** + * Constructs a Plugin object. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, SerializerInterface $serializer, array $serializer_formats) { + parent::__construct($configuration, $plugin_id, $plugin_definition); - $container = \Drupal::getContainer(); - // Get the serializer service. - $this->serializer = $container->get('serializer'); - $this->formats = $container->getParameter('serializer.formats'); + $this->definition = $plugin_definition + $configuration; + $this->serializer = $serializer; + $this->formats = $serializer_formats; } /** @@ -118,10 +132,17 @@ public function render() { /** * Gets a list of all available formats that can be requested. * + * This will return the configured formats, or all formats if none have been + * selected. + * * @return array * An array of formats. */ public function getFormats() { + if (!empty($this->options['formats'])) { + return $this->options['formats']; + } + return $this->formats; }