diff --git a/core/modules/rest/rest.services.yml b/core/modules/rest/rest.services.yml index c5d390b..207333f 100644 --- a/core/modules/rest/rest.services.yml +++ b/core/modules/rest/rest.services.yml @@ -1,3 +1,6 @@ +parameters: + rest.dependencies.auth: [] + rest.dependencies.format: [] services: plugin.manager.rest: class: Drupal\rest\Plugin\Type\ResourcePluginManager @@ -32,4 +35,4 @@ services: arguments: ['rest'] rest_resource.dependencies: class: \Drupal\rest\Entity\ConfigDependencies - arguments: ['%rest.dependencies.format', '%rest.dependencies.auth%'] + arguments: ['%rest.dependencies.format%', '%rest.dependencies.auth%'] diff --git a/core/modules/rest/src/Entity/ConfigDependencies.php b/core/modules/rest/src/Entity/ConfigDependencies.php index d4794e2..0f6930f 100644 --- a/core/modules/rest/src/Entity/ConfigDependencies.php +++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -2,6 +2,7 @@ namespace Drupal\rest\Entity; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\rest\RestResourceConfigInterface; /** @@ -31,7 +32,7 @@ class ConfigDependencies { * @param string[] $available_rest_authentications * A list of available authentications. */ - public function __construct($available_rest_formats, array $available_rest_authentications) { + public function __construct(array $available_rest_formats, array $available_rest_authentications) { $this->availableRestFormats = $available_rest_formats; $this->availableRestAuthentications = $available_rest_authentications; } @@ -67,6 +68,11 @@ public function calculateDependencies(RestResourceConfigInterface $rest_config) } } } + + if (($resource_plugin = $rest_config->getResourcePlugin()) && $resource_plugin instanceof DependentPluginInterface) { + $dependencies = array_merge($dependencies, $resource_plugin->calculateDependencies()); + } + return $dependencies; } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 4acf691..715d0fd 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -31,8 +31,9 @@ * ) */ class EntityResource extends ResourceBase implements DependentPluginInterface { + /** - * Definition of the resources entity type. + * The entity type targeted by this resource. * * @var \Drupal\Core\Entity\EntityTypeInterface */ @@ -54,8 +55,7 @@ class EntityResource extends ResourceBase implements DependentPluginInterface { * @param \Psr\Log\LoggerInterface $logger * A logger instance. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, $serializer_formats, - LoggerInterface $logger) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, $serializer_formats, LoggerInterface $logger) { parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger); $this->entityType = $entity_type_manager->getDefinition($plugin_definition['entity_type']); } diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index b0a405b..7823e6c 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -108,7 +108,7 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_ // If the route has a format requirement, then verify that the // resource has it. $format_requirement = $route->getRequirement('_format'); - if ($format_requirement && $rest_resource_config->supportsFormat($method, $format_requirement)) { + if ($format_requirement && !$rest_resource_config->supportsFormat($method, $format_requirement)) { continue; } diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index a07ecfa..e4d3ed3 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -272,7 +272,7 @@ protected function enableService($resource_type, $method = 'GET', $format = NULL // get entity by id /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ $resource_config = $this->resourceConfigStorage->load($resource_config_id); - $resource_config = ($resource_config !== NULL) ? $resource_config : $this->resourceConfigStorage->create(['id' => $resource_config_id]); + $resource_config = $resource_config ?: $this->resourceConfigStorage->create(['id' => $resource_config_id]); if ($format == NULL) { $format = $this->defaultFormat; @@ -286,7 +286,8 @@ protected function enableService($resource_type, $method = 'GET', $format = NULL $resource_config->addSupportedAuthenticationProvider($method, $auth_provider); } $resource_config->save(); - } else { + } + else { foreach ($this->resourceConfigStorage->loadMultiple() as $resource_config) { $resource_config->delete(); }