core/modules/hal/src/Normalizer/ContentEntityNormalizer.php | 9 +++++++-- .../EntityTestLabel/EntityTestLabelHalJsonAnonTest.php | 10 ---------- .../src/Functional/EntityResource/Item/ItemHalJsonTestBase.php | 10 ---------- .../Functional/EntityResource/Media/MediaResourceTestBase.php | 2 -- .../src/Normalizer/EntityReferenceFieldItemNormalizer.php | 5 +++-- core/tests/Drupal/Tests/Listeners/DeprecationListener.php | 1 - 6 files changed, 10 insertions(+), 27 deletions(-) diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index 4a9f7c4..0d23358 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -179,17 +179,22 @@ public function denormalize($data, $class, $format = NULL, array $context = []) * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. + * @param array $context + * Normalization/serialization context. + * * @return string * The entity URI. */ - protected function getEntityUri(EntityInterface $entity) { + protected function getEntityUri(EntityInterface $entity, array $context = []) { // Some entity types don't provide a canonical link template, at least call // out to ->url(). if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) { return $entity->url('canonical', []); } $url = $entity->urlInfo('canonical', ['absolute' => TRUE]); - return $url->setRouteParameter('_format', 'hal_json')->toString(); + $generated_url = $url->setRouteParameter('_format', 'hal_json')->toString(TRUE); + $this->addCacheableDependency($context, $generated_url); + return $generated_url->getGeneratedUrl(); } /** diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php index f95ea5c..bcad047 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php @@ -90,14 +90,4 @@ protected function getNormalizedPostEntity() { ]; } - /** - * {@inheritdoc} - */ - protected function getExpectedCacheContexts() { - return [ - 'url.site', - 'user.permissions', - ]; - } - } diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Item/ItemHalJsonTestBase.php b/core/modules/hal/tests/src/Functional/EntityResource/Item/ItemHalJsonTestBase.php index 24157e5..dfb2e4d 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/Item/ItemHalJsonTestBase.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/Item/ItemHalJsonTestBase.php @@ -87,14 +87,4 @@ protected function getNormalizedPostEntity() { ]; } - /** - * {@inheritdoc} - */ - protected function getExpectedCacheContexts() { - return [ - 'url.site', - 'user.permissions', - ]; - } - } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php index 475a1ca..3de224a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php @@ -154,7 +154,6 @@ protected function getExpectedNormalizedEntity() { 'target_id' => (int) $file->id(), 'target_type' => 'file', 'target_uuid' => $file->uuid(), - 'url' => $file->url(), ], ], 'thumbnail' => [ @@ -166,7 +165,6 @@ protected function getExpectedNormalizedEntity() { 'target_type' => 'file', 'target_uuid' => $thumbnail->uuid(), 'title' => 'Llama', - 'url' => $thumbnail->url(), ], ], 'status' => [ diff --git a/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php b/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php index ea2e020..c0a83b7 100644 --- a/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php +++ b/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php @@ -51,8 +51,9 @@ public function normalize($field_item, $format = NULL, array $context = []) { // Add a 'url' value if there is a reference and a canonical URL. Hard // code 'canonical' here as config entities override the default $rel // parameter value to 'edit-form. - if ($url = $entity->url('canonical')) { - $values['url'] = $url; + if ($entity->hasLinkTemplate('canonical') && $url = $entity->toUrl('canonical')->toString(TRUE)) { + $this->addCacheableDependency($context, $url); + $values['url'] = $url->getGeneratedUrl(); } } return $values; diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php index 3673376..7222fdf 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php @@ -109,7 +109,6 @@ public static function getSkippedDeprecations() { 'CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', 'The Drupal\config_translation\Plugin\migrate\source\d6\I18nProfileField is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\config_translation\Plugin\migrate\source\d6\ProfileFieldTranslation', 'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation', - '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', 'Automatically creating the first item for computed fields is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\TypedData\ComputedItemListTrait instead.', ]; }