- 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 → (Open) created by Unnamed author
- 🇩🇰Denmark blymemikkel Copenhagen
Thanks, Matt! It seems to work when I replicate my steps. Created an MR with your changes.