Skip to content
Snippets Groups Projects
Commit 34eac38d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1984626 by klausi: Fixed ResourcePluginManager should implement an...

Issue #1984626 by klausi: Fixed ResourcePluginManager should implement an AlterDecorator and others.
parent d46f4d2b
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -7,10 +7,12 @@
namespace Drupal\rest\Plugin\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Component\Plugin\Factory\ReflectionFactory;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
/**
* Manages discovery and instantiation of resource plugins.
......@@ -26,7 +28,11 @@ class ResourcePluginManager extends PluginManagerBase {
*/
public function __construct(\Traversable $namespaces) {
// Create resource plugin derivatives from declaratively defined resources.
$this->discovery = new DerivativeDiscoveryDecorator(new AnnotatedClassDiscovery('rest/resource', $namespaces));
$this->discovery = new AnnotatedClassDiscovery('rest/resource', $namespaces);
$this->discovery = new DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new AlterDecorator($this->discovery, 'rest_resource');
$this->discovery = new CacheDecorator($this->discovery, 'rest');
$this->factory = new ReflectionFactory($this->discovery);
}
......
<?php
/**
* @file
* Describes hooks provided by the RESTful Web Services module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the resource plugin definitions.
*
* @param array $definitions
* The collection of resource definitions.
*/
function hook_rest_resource_alter(&$definitions) {
if (isset($definitions['entity:node'])) {
// We want to handle REST requests regarding nodes with our own plugin
// class.
$definitions['entity:node']['class'] = 'Drupal\mymodule\Plugin\rest\resource\NodeResource';
// Serialized nodes should be expanded to my specific node class.
$definitions['entity:node']['serialization_class'] = 'Drupal\mymodule\Plugin\Core\Entity\MyNode';
}
// We don't want Views to show up in the array of plugins at all.
unset($definitions['entity:view']);
}
/**
* @} End of "addtogroup hooks".
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment