diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install index 25199f6..73c6104 100644 --- a/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -5,7 +5,7 @@ * Install, update and uninstall functions for the rest module. */ -use Drupal\rest\Entity\RestResourceConfiguration; +use Drupal\rest\Entity\RestResourceConfig; /** * Implements hook_requirements(). @@ -36,9 +36,9 @@ function rest_requirements($phase) { * @todo Automatically upgrade those REST resource config entities that have the same formats/auth mechanisms for all methods to "granular: resource" in https://www.drupal.org/node/2721595. */ function rest_update_8201() { - \Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('rest_resource_configuration')); + \Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('rest_resource_config')); foreach (\Drupal::config('rest.settings')->get('resources') as $key => $resource) { - $resource = RestResourceConfiguration::create([ + $resource = RestResourceConfig::create([ 'id' => str_replace(':', '.', $key), 'granularity' => 'method', 'configuration' => $resource, diff --git a/core/modules/rest/src/Entity/ConfigDependencies.php b/core/modules/rest/src/Entity/ConfigDependencies.php index f6e7853..c581d66 100644 --- a/core/modules/rest/src/Entity/ConfigDependencies.php +++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -4,7 +4,7 @@ use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Utility\NestedArray; -use Drupal\rest\RestResourceConfigurationInterface; +use Drupal\rest\RestResourceConfigInterface; /** * Calculates rest resource config dependencies. @@ -41,7 +41,7 @@ public function __construct(array $format_providers, array $auth_providers) { /** * Calculates dependencies of a specific rest resource configuration. * - * @param \Drupal\rest\RestResourceConfigurationInterface $rest_config + * @param \Drupal\rest\RestResourceConfigInterface $rest_config * The rest configuration. * * @return string[][] @@ -49,7 +49,7 @@ public function __construct(array $format_providers, array $auth_providers) { * * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() */ - public function calculateDependencies(RestResourceConfigurationInterface $rest_config) { + public function calculateDependencies(RestResourceConfigInterface $rest_config) { $granularity = $rest_config->get('granularity'); if ($granularity === 'method') { return $this->calculateDependenciesForMethodGranularity($rest_config); @@ -62,7 +62,7 @@ public function calculateDependencies(RestResourceConfigurationInterface $rest_c /** * Calculates dependencies of a specific rest resource configuration. * - * @param \Drupal\rest\RestResourceConfigurationInterface $rest_config + * @param \Drupal\rest\RestResourceConfigInterface $rest_config * The rest configuration. * * @return string[][] @@ -70,7 +70,7 @@ public function calculateDependencies(RestResourceConfigurationInterface $rest_c * * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() */ - protected function calculateDependenciesForMethodGranularity(RestResourceConfigurationInterface $rest_config) { + protected function calculateDependenciesForMethodGranularity(RestResourceConfigInterface $rest_config) { // The dependency lists for authentication providers and formats // generated on container build. $dependencies = []; @@ -91,17 +91,13 @@ protected function calculateDependenciesForMethodGranularity(RestResourceConfigu } } - if (($resource_plugin = $rest_config->getResourcePlugin()) && $resource_plugin instanceof DependentPluginInterface) { - $dependencies = NestedArray::mergeDeep($dependencies, $resource_plugin->calculateDependencies()); - } - return $dependencies; } /** * Informs the entity that entities it depends on will be deleted. * - * @param \Drupal\rest\RestResourceConfigurationInterface $rest_config + * @param \Drupal\rest\RestResourceConfigInterface $rest_config * The rest configuration. * @param array $dependencies * An array of dependencies that will be deleted keyed by dependency type. @@ -112,7 +108,7 @@ protected function calculateDependenciesForMethodGranularity(RestResourceConfigu * * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval() */ - public function onDependencyRemoval(RestResourceConfigurationInterface $rest_config, array $dependencies) { + public function onDependencyRemoval(RestResourceConfigInterface $rest_config, array $dependencies) { $granularity = $rest_config->get('granularity'); if ($granularity === 'method') { return $this->onDependencyRemovalForMethodGranularity($rest_config, $dependencies); @@ -125,7 +121,7 @@ public function onDependencyRemoval(RestResourceConfigurationInterface $rest_con /** * Informs the entity that entities it depends on will be deleted. * - * @param \Drupal\rest\RestResourceConfigurationInterface $rest_config + * @param \Drupal\rest\RestResourceConfigInterface $rest_config * The rest configuration. * @param array $dependencies * An array of dependencies that will be deleted keyed by dependency type. @@ -134,7 +130,7 @@ public function onDependencyRemoval(RestResourceConfigurationInterface $rest_con * @return bool * TRUE if the entity has been changed as a result, FALSE if not. */ - protected function onDependencyRemovalForMethodGranularity(RestResourceConfigurationInterface $rest_config, array $dependencies) { + protected function onDependencyRemovalForMethodGranularity(RestResourceConfigInterface $rest_config, array $dependencies) { $changed = FALSE; // Only module-related dependencies can be fixed. All other types of // dependencies cannot, because they were not generated based on supported diff --git a/core/modules/rest/src/Entity/RestResourceConfig.php b/core/modules/rest/src/Entity/RestResourceConfig.php index f8b483e..f642276 100644 --- a/core/modules/rest/src/Entity/RestResourceConfig.php +++ b/core/modules/rest/src/Entity/RestResourceConfig.php @@ -6,13 +6,13 @@ use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; -use Drupal\rest\RestResourceConfigurationInterface; +use Drupal\rest\RestResourceConfigInterface; /** * Defines a RestResourceConfig configuration entity class. * * @ConfigEntityType( - * id = "rest_resource_configuration", + * id = "rest_resource_config", * label = @Translation("REST resource configuration"), * config_prefix = "resource", * admin_permission = "administer rest resources", @@ -28,7 +28,7 @@ * } * ) */ -class RestResourceConfiguration extends ConfigEntityBase implements RestResourceConfigurationInterface { +class RestResourceConfig extends ConfigEntityBase implements RestResourceConfigInterface { /** * The REST resource config id. diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 1509610..2c3310a 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -45,7 +45,7 @@ public function __construct(EntityStorageInterface $entity_storage) { * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('entity_type.manager')->getStorage('rest_resource_configuration')); + return new static($container->get('entity_type.manager')->getStorage('rest_resource_config')); } /** @@ -63,7 +63,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) { $method = strtolower($request->getMethod()); $resource_config_id = $route_match->getRouteObject()->getDefault('_rest_resource_config'); - /** @var \Drupal\rest\RestResourceConfigurationInterface $resource_config */ + /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ $resource_config = $this->resourceStorage->load($resource_config_id); $resource = $resource_config->getResourcePlugin(); @@ -157,7 +157,7 @@ public function csrfToken() { * The serializer to use. * @param string $format * The response format. - * @param \Drupal\rest\RestResourceConfigurationInterface $resource_config + * @param \Drupal\rest\RestResourceConfigInterface $resource_config * The resource config. * * @return \Drupal\rest\ResourceResponse @@ -166,7 +166,7 @@ public function csrfToken() { * @todo Add test coverage for language negotiation contexts in * https://www.drupal.org/node/2135829. */ - protected function renderResponse(Request $request, ResourceResponseInterface $response, SerializerInterface $serializer, $format, RestResourceConfigurationInterface $resource_config) { + protected function renderResponse(Request $request, ResourceResponseInterface $response, SerializerInterface $serializer, $format, RestResourceConfigInterface $resource_config) { $data = $response->getResponseData(); if ($response instanceof CacheableResponseInterface) { diff --git a/core/modules/rest/src/RestPermissions.php b/core/modules/rest/src/RestPermissions.php index a9fe81b..473c192 100644 --- a/core/modules/rest/src/RestPermissions.php +++ b/core/modules/rest/src/RestPermissions.php @@ -36,7 +36,7 @@ class RestPermissions implements ContainerInjectionInterface { */ public function __construct(ResourcePluginManager $rest_plugin_manager, EntityTypeManagerInterface $entity_type_manager) { $this->restPluginManager = $rest_plugin_manager; - $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_configuration'); + $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config'); } /** @@ -53,7 +53,7 @@ public static function create(ContainerInterface $container) { */ public function permissions() { $permissions = []; - /** @var \Drupal\rest\RestResourceConfigurationInterface[] $resource_configs */ + /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */ $resource_configs = $this->resourceConfigStorage->loadMultiple(); foreach ($resource_configs as $resource_config) { $plugin = $resource_config->getResourcePlugin(); diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index 35b4aa2..5d3ae30 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -5,7 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\rest\Plugin\Type\ResourcePluginManager; -use Drupal\rest\RestResourceConfigurationInterface; +use Drupal\rest\RestResourceConfigInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Routing\RouteCollection; @@ -47,7 +47,7 @@ class ResourceRoutes extends RouteSubscriberBase { */ public function __construct(ResourcePluginManager $manager, EntityTypeManagerInterface $entity_type_manager, LoggerInterface $logger) { $this->manager = $manager; - $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_configuration'); + $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config'); $this->logger = $logger; } @@ -60,7 +60,7 @@ public function __construct(ResourcePluginManager $manager, EntityTypeManagerInt */ protected function alterRoutes(RouteCollection $collection) { // Iterate over all enabled REST resource configs. - /** @var \Drupal\rest\RestResourceConfigurationInterface[] $resource_configs */ + /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */ $resource_configs = $this->resourceConfigStorage->loadMultiple(); // Iterate over all enabled resource plugins. foreach ($resource_configs as $resource_config) { @@ -75,13 +75,13 @@ protected function alterRoutes(RouteCollection $collection) { * This method determines where a resource is reachable, what path * replacements are used, the required HTTP method for the operation etc. * - * @param \Drupal\rest\RestResourceConfigurationInterface $rest_resource_config + * @param \Drupal\rest\RestResourceConfigInterface $rest_resource_config * The rest resource config. * * @return \Symfony\Component\Routing\RouteCollection * The route collection. */ - protected function getRoutesForResourceConfig(RestResourceConfigurationInterface $rest_resource_config) { + protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_resource_config) { $plugin = $rest_resource_config->getResourcePlugin(); $collection = new RouteCollection(); diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index b940e11..2e96bd2 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -66,7 +66,7 @@ protected function setUp() { $this->defaultFormat = 'hal_json'; $this->defaultMimeType = 'application/hal+json'; $this->defaultAuth = array('cookie'); - $this->resourceConfigStorage = $this->container->get('entity_type.manager')->getStorage('rest_resource_configuration'); + $this->resourceConfigStorage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config'); // Create a test content type for node testing. if (in_array('node', static::$modules)) { $this->drupalCreateContentType(array('name' => 'resttest', 'type' => 'resttest')); @@ -283,7 +283,7 @@ protected function enableService($resource_type, $method = 'GET', $format = NULL // Enable REST API for this entity type. $resource_config_id = str_replace(':', '.', $resource_type); // get entity by id - /** @var \Drupal\rest\RestResourceConfigurationInterface $resource_config */ + /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ $resource_config = $this->resourceConfigStorage->load($resource_config_id); $resource_config = $resource_config ?: $this->resourceConfigStorage->create(['id' => $resource_config_id, 'granularity' => 'method', 'configuration' => []]); $configuration = $resource_config->get('configuration'); diff --git a/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php b/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php index a181685..5b9a9bc 100644 --- a/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php +++ b/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php @@ -33,7 +33,7 @@ public function setDatabaseDumpFiles() { */ public function testResourcesConvertedToConfigEntities() { /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */ - $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_configuration'); + $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config'); // Make sure we have the expected values before the update. $rest_settings = $this->config('rest.settings'); diff --git a/core/modules/rest/tests/src/Kernel/Entity/ConfigDependenciesTest.php b/core/modules/rest/tests/src/Kernel/Entity/ConfigDependenciesTest.php index 0e07b64..ddef666 100644 --- a/core/modules/rest/tests/src/Kernel/Entity/ConfigDependenciesTest.php +++ b/core/modules/rest/tests/src/Kernel/Entity/ConfigDependenciesTest.php @@ -4,7 +4,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\rest\Entity\ConfigDependencies; -use Drupal\rest\Entity\RestResourceConfiguration; +use Drupal\rest\Entity\RestResourceConfig; /** * @coversDefaultClass \Drupal\rest\Entity\ConfigDependencies @@ -25,7 +25,7 @@ class ConfigDependenciesTest extends KernelTestBase { public function testCalculateDependencies() { $config_dependencies = new ConfigDependencies(['hal_json' => 'hal', 'json' => 'serialization'], ['basic_auth' => 'basic_auth']); - $rest_config = RestResourceConfiguration::create([ + $rest_config = RestResourceConfig::create([ 'plugin_id' => 'entity:entity_test', 'granularity' => 'method', 'configuration' => [ @@ -42,7 +42,7 @@ public function testCalculateDependencies() { $result = $config_dependencies->calculateDependencies($rest_config); $this->assertEquals(['module' => [ - 'serialization', 'basic_auth', 'hal', 'entity_test', + 'serialization', 'basic_auth', 'hal', ]], $result); } @@ -53,7 +53,7 @@ public function testCalculateDependencies() { public function testOnDependencyRemovalRemoveUnrelatedDependency() { $config_dependencies = new ConfigDependencies(['hal_json' => 'hal', 'json' => 'serialization'], ['basic_auth' => 'basic_auth']); - $rest_config = RestResourceConfiguration::create([ + $rest_config = RestResourceConfig::create([ 'plugin_id' => 'entity:entity_test', 'granularity' => 'method', 'configuration' => [ @@ -88,7 +88,7 @@ public function testOnDependencyRemovalRemoveUnrelatedDependency() { public function testOnDependencyRemovalRemoveFormat() { $config_dependencies = new ConfigDependencies(['hal_json' => 'hal', 'json' => 'serialization'], ['basic_auth' => 'basic_auth']); - $rest_config = RestResourceConfiguration::create([ + $rest_config = RestResourceConfig::create([ 'plugin_id' => 'entity:entity_test', 'granularity' => 'method', 'configuration' => [ @@ -124,7 +124,7 @@ public function testOnDependencyRemovalRemoveFormat() { public function testOnDependencyRemovalRemoveAuth() { $config_dependencies = new ConfigDependencies(['hal_json' => 'hal', 'json' => 'serialization'], ['basic_auth' => 'basic_auth']); - $rest_config = RestResourceConfiguration::create([ + $rest_config = RestResourceConfig::create([ 'plugin_id' => 'entity:entity_test', 'granularity' => 'method', 'configuration' => [ @@ -160,7 +160,7 @@ public function testOnDependencyRemovalRemoveAuth() { public function testOnDependencyRemovalRemoveAuthAndFormats() { $config_dependencies = new ConfigDependencies(['hal_json' => 'hal', 'json' => 'serialization'], ['basic_auth' => 'basic_auth']); - $rest_config = RestResourceConfiguration::create([ + $rest_config = RestResourceConfig::create([ 'plugin_id' => 'entity:entity_test', 'granularity' => 'method', 'configuration' => [ diff --git a/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php b/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php index 01f8ef5..e09b175 100644 --- a/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php +++ b/core/modules/rest/tests/src/Kernel/RequestHandlerTest.php @@ -8,7 +8,7 @@ use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\RequestHandler; use Drupal\rest\ResourceResponse; -use Drupal\rest\RestResourceConfigurationInterface; +use Drupal\rest\RestResourceConfigInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; @@ -58,7 +58,7 @@ public function testBaseHandler() { ->shouldBeCalled(); // Setup the configuration. - $config = $this->prophesize(RestResourceConfigurationInterface::class); + $config = $this->prophesize(RestResourceConfigInterface::class); $config->getResourcePlugin()->willReturn($resource->reveal()); $config->getCacheContexts()->willReturn([]); $config->getCacheTags()->willReturn([]); @@ -100,7 +100,7 @@ public function testSerialization($data) { $resource = $this->prophesize(StubRequestHandlerResourcePlugin::class); // Setup the configuration. - $config = $this->prophesize(RestResourceConfigurationInterface::class); + $config = $this->prophesize(RestResourceConfigInterface::class); $config->getResourcePlugin()->willReturn($resource->reveal()); $config->getCacheContexts()->willReturn([]); $config->getCacheTags()->willReturn([]);