0
votes

I’m trying to figure out if it’s possible to customize the name of the node AEM creates when I first drop a component on the page.

The cq:Component node where my component is defined is named “knowledge-center-question” and when I drop it, AEM creates a node named “knowledge_center_que” in the page’s node tree using its default naming logic. I would prefer for the node name to be “question” when it is dropped (but I’d rather not rename the component itself).

It seems like this kind of thing must be possible given how customizable everything is in AEM, but I’m struggling to find an answer.

2

2 Answers

1
votes

You need to write a custom Sling post processor. Sling post processor is called after a component dropped in the page. Example code :

@Component(service = SlingPostProcessor.class, immediate = true, name = "com.aem.CustomPostProcessor")
public class CustomPostProcessor implements SlingPostProcessor {
  @Override
 public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception {

    if (accepts(request)) {
        final Resource resource = request.getResourceResolver().getResource(request.getResource().getPath());
        // Your logic
        modifications.add(Modification.onCreated(resource.getPath()));
    }
   }

   protected boolean accepts(SlingHttpServletRequest request) {
    return "/my/resource/type".equals(request.getResource().getResourceType());
    }

   }