core/modules/rest/rest.services.yml | 6 -- .../EventSubscriber/ResourceResponseSubscriber.php | 23 +------ core/modules/rest/src/Plugin/ResourceBase.php | 12 ---- .../RestResourceGetRouteProcessorBC.php | 80 ---------------------- core/modules/rest/src/Routing/ResourceRoutes.php | 16 +---- .../FormatSpecificGetBcRouteTestTrait.php | 50 -------------- .../Functional/Hal/EntityTestHalJsonAnonTest.php | 2 - .../src/Functional/Rest/EntityTestJsonAnonTest.php | 2 - .../Rest/EntityTestMapFieldResourceTestBase.php | 7 +- .../src/Functional/Rest/EntityTestXmlAnonTest.php | 2 - 10 files changed, 9 insertions(+), 191 deletions(-) diff --git a/core/modules/rest/rest.services.yml b/core/modules/rest/rest.services.yml index 0bc1db705c..5ffb8ded96 100644 --- a/core/modules/rest/rest.services.yml +++ b/core/modules/rest/rest.services.yml @@ -28,9 +28,3 @@ services: arguments: ['@entity_type.manager'] tags: - { name: event_subscriber } - - rest.route_processor_get_bc: - class: \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC - arguments: ['%serializer.formats%', '@router.route_provider'] - tags: - - { name: route_processor_outbound } diff --git a/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php b/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php index 229413f46a..c0efba0164 100644 --- a/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php +++ b/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php @@ -135,15 +135,6 @@ public function getResponseFormat(RouteMatchInterface $route_match, Request $req * received context. This bubbled cacheability metadata will be applied to the * the response. * - * In versions of Drupal prior to 8.5, implicit bubbling of cacheability - * metadata was allowed because there was no explicit cacheability metadata - * bubbling API. To maintain backwards compatibility, we continue to support - * this, but support for this will be dropped in Drupal 9.0.0. This is - * especially useful when interacting with APIs that implicitly invoke - * rendering (for example: generating URLs): this allows those to "leak", and - * we collect their bubbled cacheability metadata automatically in a render - * context. - * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param \Drupal\rest\ResourceResponseInterface $response @@ -167,19 +158,9 @@ protected function renderResponseBody(Request $request, ResourceResponseInterfac CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(), ]; - // @deprecated In Drupal 8.5.0, will be removed before Drupal 9.0.0. Use - // explicit cacheability metadata bubbling instead. (The wrapping call to - // executeInRenderContext() will be removed before Drupal 9.0.0.) - $context = new RenderContext(); - $output = $this->renderer - ->executeInRenderContext($context, function () use ($serializer, $data, $format, $serialization_context) { - return $serializer->serialize($data, $format, $serialization_context); - }); + $output = $serializer->serialize($data, $format, $serialization_context); + if ($response instanceof CacheableResponseInterface) { - if (!$context->isEmpty()) { - @trigger_error('Implicit cacheability metadata bubbling (onto the global render context) in normalizers is deprecated since Drupal 8.5.0 and will be removed in Drupal 9.0.0. Use the "cacheability" serialization context instead, for explicit cacheability metadata bubbling. See https://www.drupal.org/node/2918937', E_USER_DEPRECATED); - $response->addCacheableDependency($context->pop()); - } $response->addCacheableDependency($serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]); } diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index 2593004ba5..b7c4ab41c0 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -4,7 +4,6 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Routing\BcRoute; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; @@ -115,17 +114,6 @@ public function routes() { // Note that '_format' and '_content_type_format' route requirements are // added in ResourceRoutes::getRoutesForResourceConfig(). $collection->add("$route_name.$method", $route); - - // BC: the REST module originally created per-format GET routes, instead - // of a single route. To minimize the surface of this BC layer, this uses - // route definitions that are as empty as possible, plus an outbound route - // processor. - // @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC - if ($method === 'GET' || $method === 'HEAD') { - foreach ($this->serializerFormats as $format_name) { - $collection->add("$route_name.$method.$format_name", (new BcRoute())->setRequirement('_format', $format_name)); - } - } } return $collection; diff --git a/core/modules/rest/src/RouteProcessor/RestResourceGetRouteProcessorBC.php b/core/modules/rest/src/RouteProcessor/RestResourceGetRouteProcessorBC.php deleted file mode 100644 index cf5532615e..0000000000 --- a/core/modules/rest/src/RouteProcessor/RestResourceGetRouteProcessorBC.php +++ /dev/null @@ -1,80 +0,0 @@ -serializerFormats = $serializer_formats; - $this->routeProvider = $route_provider; - } - - /** - * {@inheritdoc} - */ - public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) { - $route_name_parts = explode('.', $route_name); - // BC: the REST module originally created per-format GET routes, instead - // of a single route. To minimize the surface of this BC layer, this uses - // route definitions that are as empty as possible, plus an outbound route - // processor. - // @see \Drupal\rest\Plugin\ResourceBase::routes() - if ($route_name_parts[0] === 'rest' && $route_name_parts[count($route_name_parts) - 2] === 'GET' && in_array($route_name_parts[count($route_name_parts) - 1], $this->serializerFormats, TRUE)) { - array_pop($route_name_parts); - $redirected_route_name = implode('.', $route_name_parts); - @trigger_error(sprintf("The '%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the '%s' route instead.", $route_name, $redirected_route_name), E_USER_DEPRECATED); - static::overwriteRoute($route, $this->routeProvider->getRouteByName($redirected_route_name)); - } - } - - /** - * Overwrites one route's metadata with the other's. - * - * @param \Symfony\Component\Routing\Route $target_route - * The route whose metadata to overwrite. - * @param \Symfony\Component\Routing\Route $source_route - * The route whose metadata to read from. - * - * @see \Symfony\Component\Routing\Route - */ - protected static function overwriteRoute(Route $target_route, Route $source_route) { - $target_route->setPath($source_route->getPath()); - $target_route->setDefaults($source_route->getDefaults()); - $target_route->setRequirements($source_route->getRequirements()); - $target_route->setOptions($source_route->getOptions()); - $target_route->setHost($source_route->getHost()); - $target_route->setSchemes($source_route->getSchemes()); - $target_route->setMethods($source_route->getMethods()); - } - -} diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index 0588a01219..38652244f7 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -92,11 +92,9 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_ /** @var \Symfony\Component\Routing\Route $route */ // @todo: Are multiple methods possible here? $methods = $route->getMethods(); - // Only expose routes - // - that have an explicit method and allow >=1 format for that method - // - that exist for BC - // @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC - if (($methods && ($method = $methods[0]) && $supported_formats = $rest_resource_config->getFormats($method)) || $route->hasOption('bc_route')) { + // Only expose routes that have an explicit method and allow >=1 format + // for that method. + if (($methods && ($method = $methods[0]) && $supported_formats = $rest_resource_config->getFormats($method))) { $route->setRequirement('_csrf_request_header_token', 'TRUE'); // Check that authentication providers are defined. @@ -111,14 +109,6 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_ continue; } - // Remove BC routes for unsupported formats. - if ($route->getOption('bc_route') === TRUE) { - $format_requirement = $route->getRequirement('_format'); - if ($format_requirement && !in_array($format_requirement, $rest_resource_config->getFormats($method))) { - continue; - } - } - // The configuration has been validated, so we update the route to: // - set the allowed response body content types/formats for methods // that may send response bodies (unless hardcoded by the plugin) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php b/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php deleted file mode 100644 index 54bf816c29..0000000000 --- a/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php +++ /dev/null @@ -1,50 +0,0 @@ -provisionEntityResource(); - $url = $this->getEntityResourceUrl(); - - // BC: Format-specific GET routes are deprecated. They are available on both - // new and old sites, but trigger deprecation notices. - $bc_route = Url::fromRoute('rest.entity.' . static::$entityTypeId . '.GET.' . static::$format, $url->getRouteParameters(), $url->getOptions()); - $bc_route->setUrlGenerator($this->container->get('url_generator')); - $this->expectDeprecation(sprintf("The 'rest.entity.entity_test.GET.%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the 'rest.entity.entity_test.GET' route instead.", static::$format)); - $this->assertSame($url->toString(TRUE)->getGeneratedUrl(), $bc_route->toString(TRUE)->getGeneratedUrl()); - } - - /** - * @group legacy - * - * @see \Drupal\rest\Plugin\ResourceBase::routes - */ - public function testNoFormatSpecificGetBcRouteForOtherFormats() { - $this->setExpectedException(RouteNotFoundException::class); - - $this->provisionEntityResource(); - $url = $this->getEntityResourceUrl(); - - // Verify no format-specific GET BC routes are created for other formats. - $other_format = static::$format === 'json' ? 'xml' : 'json'; - $bc_route_other_format = Url::fromRoute('rest.entity.entity_test.GET.' . $other_format, $url->getRouteParameters(), $url->getOptions()); - $bc_route_other_format->setUrlGenerator($this->container->get('url_generator')); - $bc_route_other_format->toString(TRUE); - } - -} diff --git a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Hal/EntityTestHalJsonAnonTest.php b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Hal/EntityTestHalJsonAnonTest.php index c272a1aa6f..772de556e2 100644 --- a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Hal/EntityTestHalJsonAnonTest.php +++ b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Hal/EntityTestHalJsonAnonTest.php @@ -5,7 +5,6 @@ use Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase; use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait; use Drupal\Tests\rest\Functional\AnonResourceTestTrait; -use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait; use Drupal\user\Entity\User; /** @@ -15,7 +14,6 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase { use HalEntityNormalizationTrait; use AnonResourceTestTrait; - use FormatSpecificGetBcRouteTestTrait; /** * {@inheritdoc} diff --git a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonAnonTest.php b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonAnonTest.php index 58d15b3aa2..d3808cb04a 100644 --- a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonAnonTest.php +++ b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonAnonTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\entity_test\Functional\Rest; use Drupal\Tests\rest\Functional\AnonResourceTestTrait; -use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait; /** * @group rest @@ -11,7 +10,6 @@ class EntityTestJsonAnonTest extends EntityTestResourceTestBase { use AnonResourceTestTrait; - use FormatSpecificGetBcRouteTestTrait; /** * {@inheritdoc} diff --git a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php index eae226cfa0..03b9d903eb 100644 --- a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php +++ b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php @@ -3,14 +3,12 @@ namespace Drupal\Tests\entity_test\Functional\Rest; use Drupal\entity_test\Entity\EntityTestMapField; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\Tests\Traits\ExpectDeprecationTrait; use Drupal\user\Entity\User; abstract class EntityTestMapFieldResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; use ExpectDeprecationTrait; /** @@ -99,7 +97,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'user_id' => [ [ diff --git a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestXmlAnonTest.php b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestXmlAnonTest.php index a5548f9a78..f300c15905 100644 --- a/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestXmlAnonTest.php +++ b/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestXmlAnonTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\entity_test\Functional\Rest; use Drupal\Tests\rest\Functional\AnonResourceTestTrait; -use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait; use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait; /** @@ -12,7 +11,6 @@ class EntityTestXmlAnonTest extends EntityTestResourceTestBase { use AnonResourceTestTrait; - use FormatSpecificGetBcRouteTestTrait; use XmlEntityNormalizationQuirksTrait; /**