summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-05-10 10:29:16 (GMT)
committerNathaniel Catchpole2016-05-10 10:29:16 (GMT)
commite039fa2dac692f3bb5d971298b61b16c531a3658 (patch)
tree5abffd1ee7a4fab822ffe54ab7a35d849135a02e
parentdf74821d4eab9e8c952d66994b6770c56f46d381 (diff)
Issue #2579235 by kylebrowning, willzyx: Resource plugin manager needlessly calls wrong method to instantiate plugins
-rw-r--r--core/modules/rest/src/Plugin/Type/ResourcePluginManager.php4
-rw-r--r--core/modules/rest/src/RequestHandler.php2
-rw-r--r--core/modules/rest/src/RestPermissions.php4
-rw-r--r--core/modules/rest/src/Routing/ResourceRoutes.php3
-rw-r--r--core/modules/rest/tests/src/Kernel/RequestHandlerTest.php4
5 files changed, 10 insertions, 7 deletions
diff --git a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php
index 9a3587c..4aa46b2 100644
--- a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php
+++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php
@@ -36,6 +36,10 @@ class ResourcePluginManager extends DefaultPluginManager {
/**
* {@inheritdoc}
+ *
+ * @deprecated in Drupal 8.2.0.
+ * Use Drupal\rest\Plugin\Type\ResourcePluginManager::createInstance()
+ * instead.
*/
public function getInstance(array $options){
if (isset($options['id'])) {
diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php
index 4ccc6ac..8e0cd74 100644
--- a/core/modules/rest/src/RequestHandler.php
+++ b/core/modules/rest/src/RequestHandler.php
@@ -38,7 +38,7 @@ class RequestHandler implements ContainerAwareInterface {
$resource = $this->container
->get('plugin.manager.rest')
- ->getInstance(array('id' => $plugin));
+ ->createInstance($plugin);
// Deserialize incoming data if available.
$serializer = $this->container->get('serializer');
diff --git a/core/modules/rest/src/RestPermissions.php b/core/modules/rest/src/RestPermissions.php
index 5733ef2..57e95e4 100644
--- a/core/modules/rest/src/RestPermissions.php
+++ b/core/modules/rest/src/RestPermissions.php
@@ -55,8 +55,8 @@ class RestPermissions implements ContainerInjectionInterface {
$permissions = [];
$resources = $this->configFactory->get('rest.settings')->get('resources');
if ($resources && $enabled = array_intersect_key($this->restPluginManager->getDefinitions(), $resources)) {
- foreach ($enabled as $key => $resource) {
- $plugin = $this->restPluginManager->getInstance(['id' => $key]);
+ foreach ($enabled as $id => $resource) {
+ $plugin = $this->restPluginManager->createInstance($id);
$permissions = array_merge($permissions, $plugin->permissions());
}
}
diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php
index fc72150..e88f18b 100644
--- a/core/modules/rest/src/Routing/ResourceRoutes.php
+++ b/core/modules/rest/src/Routing/ResourceRoutes.php
@@ -73,8 +73,7 @@ class ResourceRoutes extends RouteSubscriberBase {
// Iterate over all enabled resource plugins.
foreach ($enabled_resources as $id => $enabled_methods) {
- $plugin = $this->manager->getInstance(array('id' => $id));
-
+ $plugin = $this->manager->createInstance($id);
foreach ($plugin->routes() as $name => $route) {
// @todo: Are multiple methods possible here?
$methods = $route->getMethods();
diff --git a/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php b/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php
index 6c19ca4..36a482c 100644
--- a/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php
+++ b/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php
@@ -55,7 +55,7 @@ class RequestHandlerTest extends KernelTestBase {
// Setup stub plugin manager that will return our plugin.
$stub = $this->prophesize(ResourcePluginManager::class);
- $stub->getInstance(['id' => 'restplugin'])
+ $stub->createInstance('restplugin')
->willReturn($resource->reveal());
$this->container->set('plugin.manager.rest', $stub->reveal());
@@ -95,7 +95,7 @@ class RequestHandlerTest extends KernelTestBase {
// Setup stub plugin manager that will return our plugin.
$stub = $this->prophesize(ResourcePluginManager::class);
- $stub->getInstance(['id' => 'restplugin'])
+ $stub->createInstance('restplugin')
->willReturn($resource->reveal());
$this->container->set('plugin.manager.rest', $stub->reveal());