- Issue created by @blymemikkel
- 🇺🇸United States mglaman WI, USA
The generated URL has the associated metadata but doesn't capture it.
$url = Url::fromUri($data['uri'], ['language' => $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)]); // Use absolute urls if configured. $configuration = $this->getConfiguration(); if ($configuration['absolute_url']) { $url->setAbsolute(TRUE); } $data['url'] = $url->toString(); }
From the field item normalizer:
$context = new Context($context); $context->offsetSet('field_item_object', $object); $context->offsetSet(CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY, $cacheability); $processed = $enhancer->undoTransform( $normalized_output->getNormalization(), $context );
The fix is something like
$generatedUrl = $url->toString(TRUE); $context->offsetGet(CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY)->addCacheableDependency($url); $data['url'] = $generatedUrl->getGeneratedUrl();
- Merge request !60fix(UrlLinkEnhancer): Add cacheability metadata to generated URLs → (Merged) created by Unnamed author
- 🇩🇰Denmark blymemikkel Copenhagen
Thanks, Matt! It seems to work when I replicate my steps. Created an MR with your changes.
- First commit to issue fork.
- 🇳🇱Netherlands bbrala Netherlands
This is awesome, thank you so much. Looking good :)
- Status changed to Fixed
4 months ago 11:59am 20 December 2024 Automatically closed - issue fixed for 2 weeks with no activity.