Conversation
rolfvandekrol
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
See comments on ContentEntityNormalizer.
… other than image.
No description provided.