Skip to content

Conversation

@ashwinimone
Copy link
Contributor

No description provided.

Copy link
Contributor

@rolfvandekrol rolfvandekrol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks very good. Just two small changes with regards to cache metadata and it's completely done 👍

foreach ($object->getTranslationLanguages() as $language) {
$data['language_links'][$language->getId()] = $object->getTranslation($language->getId())->url('canonical');
if ($object->hasLinkTemplate('canonical') && $url = $object->getTranslation($language->getId())->toUrl('canonical')->toString(TRUE)) {
$data['language_links'][$language->getId()] = $url->getGeneratedUrl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are getting the URL in string form you are requesting the cache metadata as well (that's the TRUE, in the argument of toString), but in this line you are only using the generated URL itself and disregard the cache metadata. You should either request the URL without it's cache metadata (not recommended) or add the cache metadata to the cache metadata of the normalizer response (recommended). The code for that is $this->addCacheableDependency($context, $url);. The same applies to the EntityReferenceFieldItemNormalizer, and while I was reading through that file I noticed that later in the file the field item is added as a cacheable dependency, but manually instead of through that helper function, so maybe fix that as well.

if ($url = $entity->url('canonical')) {
$values['url'] = $url;
if ($entity->hasLinkTemplate('canonical') && !$entity->isNew() && $url = $entity->toUrl('canonical')->toString(TRUE)) {
$values['url'] = $url->getGeneratedUrl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments on ContentEntityNormalizer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants