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!

Files: 
CommentFileSizeAuthor
#5 plugin-alter-1984626-5.patch2.65 KBklausi
PASSED: [[SimpleTest]]: [MySQL] 55,979 pass(es). View
#5 plugin-alter-1984626-5-interdiff.txt466 bytesklausi
#3 plugin-alter-1984626-3.patch2.65 KBklausi
PASSED: [[SimpleTest]]: [MySQL] 55,675 pass(es). View
#2 rest-plugin-alter-1984626-2.patch2.49 KBklausi
PASSED: [[SimpleTest]]: [MySQL] 55,926 pass(es). View

Comments

tim.plunkett’s picture

Issue tags: +Plugin system

+1

klausi’s picture

Status: Active » Needs review
FileSize
2.49 KB
PASSED: [[SimpleTest]]: [MySQL] 55,926 pass(es). View

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

FileSize
2.65 KB
PASSED: [[SimpleTest]]: [MySQL] 55,675 pass(es). View

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

FileSize
466 bytes
2.65 KB
PASSED: [[SimpleTest]]: [MySQL] 55,979 pass(es). View

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.