Skip to content

Commit

Permalink
Fix fallback i18nContentSupport (MgnlContext not present issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Jan 10, 2025
1 parent 258cb36 commit d3423b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.merkle.oss.magnolia.powernode;

import info.magnolia.cms.i18n.I18nContentSupport;
import info.magnolia.module.site.Site;
import info.magnolia.module.site.SiteManager;

import java.util.Locale;
Expand All @@ -13,8 +14,11 @@
public abstract class AbstractLocalizedNameProvider implements LocalizedNameProvider {
private final Function<Optional<Node>, I18nContentSupport> i18nContentSupportProvider;

protected AbstractLocalizedNameProvider(final SiteManager siteManager) {
this.i18nContentSupportProvider = (node) -> node.map(siteManager::getAssignedSite).orElseGet(siteManager::getCurrentSite).getI18n();
protected AbstractLocalizedNameProvider(
final SiteManager siteManager,
final I18nContentSupport i18nContentSupport
) {
this.i18nContentSupportProvider = (node) -> node.map(siteManager::getAssignedSite).map(Site::getI18n).orElse(i18nContentSupport);
}

protected AbstractLocalizedNameProvider(final Function<Optional<Node>, I18nContentSupport> i18nContentSupportProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
public class MagnoliaDefaultLocalizedNameProvider extends AbstractLocalizedNameProvider {

@Inject
public MagnoliaDefaultLocalizedNameProvider(final SiteManager siteManager) {
super(siteManager);
public MagnoliaDefaultLocalizedNameProvider(
final SiteManager siteManager,
final I18nContentSupport i18nContentSupport
) {
super(siteManager, i18nContentSupport);
}

protected MagnoliaDefaultLocalizedNameProvider(final Function<Optional<Node>, I18nContentSupport> i18nContentSupportProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
public class MagnoliaLanguageLocalizedNameProvider extends AbstractLocalizedNameProvider {

@Inject
public MagnoliaLanguageLocalizedNameProvider(final SiteManager siteManager) {
super(siteManager);
public MagnoliaLanguageLocalizedNameProvider(
final SiteManager siteManager,
final I18nContentSupport i18nContentSupport
) {
super(siteManager, i18nContentSupport);
}

protected MagnoliaLanguageLocalizedNameProvider(final Function<Optional<Node>, I18nContentSupport> i18nContentSupportProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setUp() {
doReturn(i18nContentSupport).when(site).getI18n();
final SiteManager siteManager = mock(SiteManager.class);
doReturn(site).when(siteManager).getAssignedSite(any(Node.class));
localizedNameProvider = new MagnoliaDefaultLocalizedNameProvider(siteManager);
localizedNameProvider = new MagnoliaDefaultLocalizedNameProvider(siteManager, i18nContentSupport);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void setUp() {
doReturn(i18nContentSupport).when(site).getI18n();
final SiteManager siteManager = mock(SiteManager.class);
doReturn(site).when(siteManager).getCurrentSite();
localizedNameProvider = new MagnoliaLanguageLocalizedNameProvider(siteManager);
localizedNameProvider = new MagnoliaLanguageLocalizedNameProvider(siteManager, i18nContentSupport);
}

@Test
Expand Down

0 comments on commit d3423b2

Please sign in to comment.