adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
726 stars 735 forks source link

[Experience Fragment] Localized Fragment Variation does not take content into account #1604

Open dhardtke opened 3 years ago

dhardtke commented 3 years ago

Bug Report

Current Behavior We have a client that would like to use language roots that use the country name as page name, e.g. "us". The current implementation of the Experience Fragment does not take the content into account because it invokes https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/api/LanguageManager.html#getLanguageRoot-org.apache.sling.api.resource.Resource- which only looks at the Page name ("us" in my example) and, hence, returns null.

Expected behavior/code The code should use https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/api/LanguageManager.html#getLanguageRoot-org.apache.sling.api.resource.Resource-boolean- which allows taking the "Language Root" checkbox into account:

image

Environment

Possible Solution I will create a Pull Request that changes the call of the LanguageManager:

https://github.com/adobe/aem-core-wcm-components/blob/ac9c4a05ab44a979765db5bd9f0f7c3afc51571e/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/util/LocalizationUtils.java#L82

Additional context / Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

dhardtke commented 3 years ago

Okay, so I have spent the last hour trying to write or rather fix the current tests after changing the getLanguageRoot(resource, respectContent) call.

The problem is that https://github.com/wcm-io/wcm-io-testing/blob/develop/aem-mock/core/src/main/java/io/wcm/testing/mock/aem/MockLanguageManager.java throws an UnsupportedOperationException in that method and I believe this mock service is used in the tests. I can not verify this because I have never been able to run the tests from within my IntelliJ and can't debug them.

I am also unable to provide a custom MockLanguageManager by manually registering it using context.registerService(LanguageManager.class, new MockLanguageManager());: Can anyone help me out here?