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:

<?php
$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

Issue tags:+Plugin system

+1

Status:Active» Needs review
StatusFileSize
new2.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?

StatusFileSize
new2.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.

+++ 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

StatusFileSize
new466 bytes
new2.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

Status:Needs review» Reviewed & tested by the community

:) this looks good.

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.