Filter out Ghost Component from JSON on publish server | Community
Skip to main content
November 20, 2022
Solved

Filter out Ghost Component from JSON on publish server

  • November 20, 2022
  • 2 replies
  • 2108 views

Hi Team, 

 

If a component is deleted from a live copy page, AEM replaces it with a "ghost" component  ( wcm/msm/components/ghost ).

 

As per business requirements, 

 

I have to delete this Ghost component on publish server only but It should remain in the page model on AEM author to ensure that users can re-instate deleted components as needed.

 

 

<div data-cq-data-path="/content/weretail/home/livecopysample/jcr:content/root/decorativepanel/content/row/grid/text" class="cq-Editable-dom"><div class="aem-placeholder">Ghost Component<br><strong>wcm/msm/components/ghost</strong></div><div></div></div>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SantoshSai

this is the sling:resourceType for that componet. sling:resourceType :wcm/msm/components/ghost

 

could you please help me with that how to return the resource list except for the ghost resource? 

 

 

  protected List<ResourceListItemImpl> readItems() {
        return getChildren().stream()
            .map(res -> new ResourceListItemImpl(linkManager, res, getId(), component))
            .collect(Collectors.toList());
    }

 

 

I have one query: If we do like this, why does it filter out on publish instance, and why not in the author instance? 


@maheswaraiah_m You can execute your code conditionally by fetching runmode as below

import org.apache.felix.scr.annotations.Component;
import org.apache.sling.settings.SlingSettingsService;

@Component
public class MyService {

    @Reference
    private SlingSettingsService slingSettingsService;

    private boolean isPublish() {
        return this.slingSettingsService.getRunModes().contains("publish");
    }
}

2 replies

SantoshSai
Community Advisor
Community Advisor
November 20, 2022
November 20, 2022

Thanks @santoshsai 

I guess it won't work as I am not able to see any ".ghost" class. 

Reference: <div data-cq-data-path="/content/weretail/home/livecopysample/jcr:content/root/decorativepanel/content/row/grid/text" class="cq-Editable-dom"><div class="aem-placeholder">Ghost Component<br><strong>wcm/msm/components/ghost</strong></div><div></div></div>

 

 

SantoshSai
Community Advisor
Community Advisor
November 20, 2022

@maheswaraiah_m In DOM structure could you please check - there must be some LayoutContainer where resources are listed based on that you can go for custom implementation as mentioned in above thread.

 

Santosh Sai
B_Sravan
Community Advisor
Community Advisor
November 20, 2022

Hi @maheswaraiah_m,

the best way to deal with this is to override the layout container class through a delegation pattern and return the resource list based on run mode as told in the above components.

more on customizing the logic: https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/customizing.html?lang=en#customizing-the-logic-of-a-core-component 

 

more on delegation pattern: https://github.com/adobe/aem-core-wcm-components/wiki/Delegation-Pattern-for-Sling-Models 

Thank you.

 

-Sravan