Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

9.x #12

wants to merge 16 commits into from

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 👍

@@ -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();
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.

4 participants