.../modules/rest/src/Entity/ConfigDependencies.php | 22 ++++++++++++++++++ .../modules/rest/src/Entity/RestResourceConfig.php | 26 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/core/modules/rest/src/Entity/ConfigDependencies.php b/core/modules/rest/src/Entity/ConfigDependencies.php index 5475d0d..a36a525 100644 --- a/core/modules/rest/src/Entity/ConfigDependencies.php +++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -117,6 +117,28 @@ protected function calculateDependenciesForMethodGranularity(RestResourceConfigI * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval() */ public function onDependencyRemoval(RestResourceConfigInterface $rest_config, array $dependencies) { + $granularity = $rest_config->get('granularity'); + if ($granularity === 'method') { + return $this->onDependencyRemovalForMethodGranularity($rest_config, $dependencies); + } + else { + // @todo Add resource-level granularity support in https://www.drupal.org/node/2721595. + } + } + + /** + * Informs the entity that entities it depends on will be deleted. + * + * @param \Drupal\rest\RestResourceConfigInterface $rest_config + * The rest configuration. + * @param array $dependencies + * An array of dependencies that will be deleted keyed by dependency type. + * Dependency types are, for example, entity, module and theme. + * + * @return bool + * TRUE if the entity has been changed as a result, FALSE if not. + */ + public 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 dde5d2c..e59c38a 100644 --- a/core/modules/rest/src/Entity/RestResourceConfig.php +++ b/core/modules/rest/src/Entity/RestResourceConfig.php @@ -149,7 +149,13 @@ public function getAuthenticationProviders($method) { } /** - * {@inheritdoc} + * Retrieves a list of supported authentication providers. + * + * @param string $method + * The request method e.g GET or POST. + * + * @return string[] + * A list of supported authentication provider IDs. */ public function getAuthenticationProvidersForMethodGranularity($method) { $method = $this->normalizeRestMethod($method); @@ -163,6 +169,24 @@ public function getAuthenticationProvidersForMethodGranularity($method) { * {@inheritdoc} */ public function getFormats($method) { + if ($this->granularity === 'method') { + return $this->getFormatsForMethodGranularity($method); + } + else { + // @todo Add resource-level granularity support in https://www.drupal.org/node/2721595. + } + } + + /** + * Retrieves a list of supported response formats. + * + * @param string $method + * The request method e.g GET or POST. + * + * @return string[] + * A list of supported format IDs. + */ + protected function getFormatsForMethodGranularity($method) { $method = $this->normalizeRestMethod($method); if (in_array($method, $this->getMethods()) && isset($this->configuration[$method]['supported_formats'])) { return $this->configuration[$method]['supported_formats'];