-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
9.x #12
base: master
Are you sure you want to change the base?
9.x #12
Conversation
There was a problem hiding this 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 👍
@@ -41,7 +41,9 @@ public function normalize($object, $format = NULL, array $context = []) { | |||
|
|||
$data['language_links'] = []; | |||
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.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments on ContentEntityNormalizer
.
… other than image.
No description provided.