From 1ed0101a34a9ca202462481821419c5b28837fa3 Mon Sep 17 00:00:00 2001 From: Stefan Popescu Date: Tue, 13 Aug 2024 10:56:21 +0300 Subject: [PATCH] SITES-19836 Ghost component in container is displayed on publish and preview instances --- .../components/internal/models/v1/LayoutContainerImpl.java | 5 +++++ bundles/core/src/test/resources/container/test-content.json | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LayoutContainerImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LayoutContainerImpl.java index 5983c9f2cf..9f4493f189 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LayoutContainerImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/LayoutContainerImpl.java @@ -22,6 +22,7 @@ import javax.annotation.PostConstruct; +import com.day.cq.wcm.api.WCMMode; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; @@ -44,6 +45,7 @@ public class LayoutContainerImpl extends AbstractContainerImpl implements Layout * The resource type. */ protected static final String RESOURCE_TYPE_V1 = "core/wcm/components/container/v1/container"; + protected static final String GHOST_COMPONENT_RESOURCE_TYPE = "wcm/msm/components/ghost"; /** * The layout type. @@ -103,7 +105,10 @@ protected final List readItems() { @Override public final List getChildren() { if (this.items == null) { + WCMMode wcmMode = WCMMode.fromRequest(this.request); + boolean showGhostComponent = wcmMode == WCMMode.EDIT; this.items = ComponentUtils.getChildComponents(this.resource, this.request).stream() + .filter(item -> showGhostComponent || !GHOST_COMPONENT_RESOURCE_TYPE.equals(item.getResourceType())) .map(ContainerItemImpl::new) .collect(Collectors.toList()); } diff --git a/bundles/core/src/test/resources/container/test-content.json b/bundles/core/src/test/resources/container/test-content.json index aaec08324a..281438bbee 100644 --- a/bundles/core/src/test/resources/container/test-content.json +++ b/bundles/core/src/test/resources/container/test-content.json @@ -31,6 +31,12 @@ "jcr:description" : "Teaser 2 description", "sling:resourceType": "core/wcm/components/teaser/v1/teaser" }, + "item_ghost": { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Ghost", + "jcr:description" : "Ghost component", + "sling:resourceType": "wcm/msm/components/ghost" + }, "item_3": {} }, "container-2" : {