aem-core-wcm-components icon indicating copy to clipboard operation
aem-core-wcm-components copied to clipboard

Alternative Language Links Missing when Language Nav is templated from structure

Open HitmanInWis opened this issue 1 year ago • 0 comments

Version: 2.24.7-SNAPSHOT

Bug Report

If the language nav on the page is within the Structure portion of an Experience Fragment, it is not detected, and thus the Alternative Language links are missing from the page

.

The bug is in LanguageNavigationSiteRootSelectionStrategy::findFirst - in searching for a Language Nav component, it correctly finds Experience Fragment References and searches the linked Experience Fragments for Language Nav, but if the XF itself does not have the Language Nav node (because it is coming from a template structure) then the code wont find it.

The solution is simple - update the following code

            return Optional.ofNullable(resource.adaptTo(ExperienceFragmentDataImpl.class))
                .map(ExperienceFragmentDataImpl::getLocalizedFragmentVariationPath)
                .map(xfPath -> resource.getResourceResolver().getResource(xfPath))
                .flatMap(xfResource -> findFirst(xfResource, condition, containingPage));

to

            return Optional.ofNullable(resource.adaptTo(ExperienceFragmentDataImpl.class))
                .map(ExperienceFragmentDataImpl::getLocalizedFragmentVariationPath)
                .map(xfPath -> resource.getResourceResolver().getResource(xfPath))
                .map(xfResource -> ComponentUtils.getEffectiveResource(xfResource, null))  // this is new code
                .flatMap(xfResource -> findFirst(xfResource, condition, containingPage));

As a side note, LanguageNavigationSiteRootSelectionStrategy#findLanguageNavigation(org.apache.sling.api.resource.Resource, com.day.cq.wcm.api.Page) should also be refactored to use ComponentUtils.getEffectiveResource(contentResource, null)

HitmanInWis avatar May 21 '24 19:05 HitmanInWis