Commit e3da828f authored by alexpott's avatar alexpott

Issue #2397271 by Wim Leers, larowlan, penyaskito, MattA: REST configuration...

Issue #2397271 by Wim Leers, larowlan, penyaskito, MattA: REST configuration fails if it contains a plugin reference that does not exist
parent dc89c492
...@@ -64,7 +64,17 @@ public function __construct(ResourcePluginManager $manager, ConfigFactoryInterfa ...@@ -64,7 +64,17 @@ public function __construct(ResourcePluginManager $manager, ConfigFactoryInterfa
*/ */
protected function alterRoutes(RouteCollection $collection) { protected function alterRoutes(RouteCollection $collection) {
$routes = array(); $routes = array();
$enabled_resources = $this->config->get('rest.settings')->get('resources') ?: array();
// Silently ignore resources that are in the settings but are not defined on
// the plugin manager currently. That avoids exceptions when REST module is
// enabled before another module that provides the resource plugin specified
// in the settings.
// @todo Remove in https://www.drupal.org/node/2308745
$resources = $this->config->get('rest.settings')->get('resources') ?: array();
$enabled_resources = array_intersect_key($resources, $this->manager->getDefinitions());
if (count($resources) != count($enabled_resources)) {
trigger_error('rest.settings lists resources relying on the following missing plugins: ' . implode(', ', array_keys(array_diff_key($resources, $enabled_resources))));
}
// 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) {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
*/ */
namespace Drupal\rest\Tests; namespace Drupal\rest\Tests;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role; use Drupal\user\Entity\Role;
...@@ -121,4 +123,30 @@ public function testUriPaths() { ...@@ -121,4 +123,30 @@ public function testUriPaths() {
} }
} }
/**
* Tests that a resource with a missing plugin does not cause an exception.
*/
public function testMissingPlugin() {
$settings = array(
'entity:nonexisting' => array(
'GET' => array(
'supported_formats' => array(
'hal_json',
),
),
),
);
try {
// Attempt to enable the resource.
$this->config->set('resources', $settings);
$this->config->save();
$this->rebuildCache();
$this->pass('rest.settings referencing a missing REST resource plugin does not cause an exception.');
}
catch (PluginNotFoundException $e) {
$this->fail('rest.settings referencing a missing REST resource plugin caused an exception.');
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment