Skip to content
Snippets Groups Projects
Commit e039fa2d authored by catch's avatar catch
Browse files

Issue #2579235 by kylebrowning, willzyx: Resource plugin manager needlessly...

Issue #2579235 by kylebrowning, willzyx: Resource plugin manager needlessly calls wrong method to instantiate plugins
parent df74821d
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
...@@ -36,6 +36,10 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac ...@@ -36,6 +36,10 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated in Drupal 8.2.0.
* Use Drupal\rest\Plugin\Type\ResourcePluginManager::createInstance()
* instead.
*/ */
public function getInstance(array $options){ public function getInstance(array $options){
if (isset($options['id'])) { if (isset($options['id'])) {
......
...@@ -38,7 +38,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) { ...@@ -38,7 +38,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) {
$resource = $this->container $resource = $this->container
->get('plugin.manager.rest') ->get('plugin.manager.rest')
->getInstance(array('id' => $plugin)); ->createInstance($plugin);
// Deserialize incoming data if available. // Deserialize incoming data if available.
$serializer = $this->container->get('serializer'); $serializer = $this->container->get('serializer');
......
...@@ -55,8 +55,8 @@ public function permissions() { ...@@ -55,8 +55,8 @@ public function permissions() {
$permissions = []; $permissions = [];
$resources = $this->configFactory->get('rest.settings')->get('resources'); $resources = $this->configFactory->get('rest.settings')->get('resources');
if ($resources && $enabled = array_intersect_key($this->restPluginManager->getDefinitions(), $resources)) { if ($resources && $enabled = array_intersect_key($this->restPluginManager->getDefinitions(), $resources)) {
foreach ($enabled as $key => $resource) { foreach ($enabled as $id => $resource) {
$plugin = $this->restPluginManager->getInstance(['id' => $key]); $plugin = $this->restPluginManager->createInstance($id);
$permissions = array_merge($permissions, $plugin->permissions()); $permissions = array_merge($permissions, $plugin->permissions());
} }
} }
......
...@@ -73,8 +73,7 @@ protected function alterRoutes(RouteCollection $collection) { ...@@ -73,8 +73,7 @@ protected function alterRoutes(RouteCollection $collection) {
// Iterate over all enabled resource plugins. // Iterate over all enabled resource plugins.
foreach ($enabled_resources as $id => $enabled_methods) { 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) { foreach ($plugin->routes() as $name => $route) {
// @todo: Are multiple methods possible here? // @todo: Are multiple methods possible here?
$methods = $route->getMethods(); $methods = $route->getMethods();
......
...@@ -55,7 +55,7 @@ public function testBaseHandler() { ...@@ -55,7 +55,7 @@ public function testBaseHandler() {
// Setup stub plugin manager that will return our plugin. // Setup stub plugin manager that will return our plugin.
$stub = $this->prophesize(ResourcePluginManager::class); $stub = $this->prophesize(ResourcePluginManager::class);
$stub->getInstance(['id' => 'restplugin']) $stub->createInstance('restplugin')
->willReturn($resource->reveal()); ->willReturn($resource->reveal());
$this->container->set('plugin.manager.rest', $stub->reveal()); $this->container->set('plugin.manager.rest', $stub->reveal());
...@@ -95,7 +95,7 @@ public function testSerialization($data) { ...@@ -95,7 +95,7 @@ public function testSerialization($data) {
// Setup stub plugin manager that will return our plugin. // Setup stub plugin manager that will return our plugin.
$stub = $this->prophesize(ResourcePluginManager::class); $stub = $this->prophesize(ResourcePluginManager::class);
$stub->getInstance(['id' => 'restplugin']) $stub->createInstance('restplugin')
->willReturn($resource->reveal()); ->willReturn($resource->reveal());
$this->container->set('plugin.manager.rest', $stub->reveal()); $this->container->set('plugin.manager.rest', $stub->reveal());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment