From 269160422e9cf97ae2aaa4deba3db85a73e0c4a8 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Tue, 29 Oct 2024 13:21:57 +0100 Subject: [PATCH] fix: Preserve Data when duplicating Image or Link Portlet - MEED-7687 - Meeds-io/MIPs#165 (#247) Prior to this change, when the Image or Link Portlet doesn't have been initialized/displayed yet in a page, like the default Space Templates, the 'data.init' preference isn't used to initialize the portlet yet and thus when duplicating the page template, the 'data.init' has to be reused instead of generated only when the CMS portlet is initialized. --- .../renderer/ImagePortletInstancePreferencePlugin.java | 5 +++++ .../plugin/renderer/LinkPortletInstancePreferencePlugin.java | 5 +++++ .../io/meeds/layout/service/NavigationLayoutService.java | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/layout-service/src/main/java/io/meeds/layout/plugin/renderer/ImagePortletInstancePreferencePlugin.java b/layout-service/src/main/java/io/meeds/layout/plugin/renderer/ImagePortletInstancePreferencePlugin.java index a234c9fa..d4e58019 100644 --- a/layout-service/src/main/java/io/meeds/layout/plugin/renderer/ImagePortletInstancePreferencePlugin.java +++ b/layout-service/src/main/java/io/meeds/layout/plugin/renderer/ImagePortletInstancePreferencePlugin.java @@ -68,6 +68,11 @@ public String getPortletName() { @SneakyThrows public List generatePreferences(Application application, Portlet preferences) { + if (preferences != null && preferences.getPreference(DATA_INIT_PREFERENCE_NAME) != null) { + return Collections.singletonList(new PortletInstancePreference(DATA_INIT_PREFERENCE_NAME, + preferences.getPreference(DATA_INIT_PREFERENCE_NAME) + .getValue())); + } String settingName = getCmsSettingName(preferences); if (StringUtils.isBlank(settingName)) { return Collections.emptyList(); diff --git a/layout-service/src/main/java/io/meeds/layout/plugin/renderer/LinkPortletInstancePreferencePlugin.java b/layout-service/src/main/java/io/meeds/layout/plugin/renderer/LinkPortletInstancePreferencePlugin.java index aa01c01b..2021e138 100644 --- a/layout-service/src/main/java/io/meeds/layout/plugin/renderer/LinkPortletInstancePreferencePlugin.java +++ b/layout-service/src/main/java/io/meeds/layout/plugin/renderer/LinkPortletInstancePreferencePlugin.java @@ -56,6 +56,11 @@ public String getPortletName() { @SneakyThrows public List generatePreferences(Application application, Portlet preferences) { + if (preferences != null && preferences.getPreference(DATA_INIT_PREFERENCE_NAME) != null) { + return Collections.singletonList(new PortletInstancePreference(DATA_INIT_PREFERENCE_NAME, + preferences.getPreference(DATA_INIT_PREFERENCE_NAME) + .getValue())); + } String settingName = getCmsSettingName(preferences); if (StringUtils.isBlank(settingName)) { return Collections.emptyList(); diff --git a/layout-service/src/main/java/io/meeds/layout/service/NavigationLayoutService.java b/layout-service/src/main/java/io/meeds/layout/service/NavigationLayoutService.java index 813cbc0e..8023b8fe 100644 --- a/layout-service/src/main/java/io/meeds/layout/service/NavigationLayoutService.java +++ b/layout-service/src/main/java/io/meeds/layout/service/NavigationLayoutService.java @@ -37,7 +37,6 @@ import org.exoplatform.commons.exception.ObjectNotFoundException; import org.exoplatform.commons.utils.ExpressionUtil; import org.exoplatform.portal.application.PortalRequestHandler; -import org.exoplatform.portal.application.PortalTemplateRequestHandler; import org.exoplatform.portal.config.model.PortalConfig; import org.exoplatform.portal.mop.SiteKey; import org.exoplatform.portal.mop.SiteType; @@ -62,6 +61,7 @@ import io.meeds.layout.model.NavigationCreateModel; import io.meeds.layout.model.NavigationUpdateModel; import io.meeds.layout.model.NodeLabel; +import io.meeds.portal.web.handler.PortalTemplateRequestHandler; @Service public class NavigationLayoutService {