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

Filter out Ghost Component from JSON on publish server

  • November 20, 2022
  • 2 replies
  • 2122 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
Level 2
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>

 

 

Magicr
Level 6
November 22, 2022

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  A side question: It seems the method "getChildren()" is selfcreated. As far as I understood you do not want to keep the content from ghos component. Would it be an option to delete this resource during executing "getChildren()" only on publish instance?

 

Another option would be creating an event lister which calls a service which removes all resource of ghost components. You can using sql2 to find all occurences.

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