We want all the discovery things for ResourcePluginManager to make it more powerful.

The first thing that comes to mind is swapping out a plugin definition. Example: I'm a contrib module and I'm really not happy how the entity:node resource plugin works, so I want to alter it because I want to treat REST requests for nodes in a more specific way.

Basically we can copy from ViewsPluginManager:

$this->discovery = new AnnotatedClassDiscovery('views', $type, $namespaces);
$this->discovery = new DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));
$this->discovery = new AlterDecorator($this->discovery, 'views_plugins_' . $type);
$this->discovery = new CacheDecorator($this->discovery, 'views:' . $type, 'views_info');

ProcessDecorator does not make sense to me, but we want the rest!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Issue tags: +Plugin system

+1

klausi’s picture

Status: Active » Needs review
FileSize
2.49 KB

Here is a start that adds the AlterDecorator + api.php docs.

Not sure about the CacheDecorator, should we add our own cache bin? Do we even need a cache?

klausi’s picture

It looks like it is pretty easy to use the cache decorator as well with the default cache bin, so I added that here.

tim.plunkett’s picture

+++ b/core/modules/rest/rest.api.phpundefined
@@ -0,0 +1,33 @@
+ * Alters the resource plugin definitions.

Should say "Alter", api.php stuff is different

+++ b/core/modules/rest/rest.api.phpundefined
@@ -0,0 +1,33 @@
+ * @param array &$definitions

We don't put the & here

klausi’s picture

Fixed both, although the second one is not defined in the coding standards and I personally think it is very valuable information to have the reference "&" there. But anyway, if this buys me an RTBC I'll "fix" anything you say :-P

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

:) this looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Contrib will thank you! No need for tests as the functionality of AlterDecorator and CacheDecorator are tested elsewhere.

Committed 34eac38 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.