content fragments content inheritance | Community
Skip to main content
sreenu539
August 7, 2024
Solved

content fragments content inheritance

  • August 7, 2024
  • 2 replies
  • 736 views

hi,

 

I have content fragment created. It has master, sub-variation-one, sub-variation-two.

 

Use case: change different fields in master variation, expecting changes to reflect in sub-variation.

 

Based on documentation : https://experienceleague.adobe.com/en/docs/experience-manager-65/content/assets/content-fragments/content-fragments-variations#synchronizing-with-master

 

CAUTION
Synchronization is only available to copy changes from Master to the variation.
Only the current element of the variation is synchronized.
Synchronization only works on the Multi line text data type.
Transferring changes from a variation to Master is not available as an option.
 
only multi line text has sync capability. My client wants all the other data types data also synced.
 
How can I achieve this?
 
Thanks,
Sri
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 Pradeep_Kumar_Srivastav

Hi @sreenu539 , I think an Adobe support ticket will get help with this as an enhancement but for now maybe you can create an Event Listener to listen for changes to the content fragment resources and trigger the synchronization process. Something like below to check if this works as expected.

 

@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_TOPIC + "=" + PageEvent.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=(path=/content/dam/*)"
})
public class ContentFragmentEventListener implements EventHandler {

@Reference
private ResourceResolverFactory resolverFactory;

@Override
public void handleEvent(Event event) {
PageEvent pageEvent = (PageEvent) event;
for (ResourceChange change : pageEvent.getChanges()) {
try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(null)) {
Resource resource = resolver.getResource(change.getPath());
if (resource != null && isContentFragment(resource)) {
CustomContentFragmentModel model = resource.adaptTo(CustomContentFragmentModel.class);
model.synchronizeVariations(resource.getChild("jcr:content"));
}
} catch (LoginException e) {
// Handle exception
}
}
}

private boolean isContentFragment(Resource resource) {
return resource.getResourceType().equals("dam:Asset");
}
}

2 replies

Pradeep_Kumar_Srivastav
Community Advisor
Pradeep_Kumar_SrivastavCommunity AdvisorAccepted solution
Community Advisor
August 8, 2024

Hi @sreenu539 , I think an Adobe support ticket will get help with this as an enhancement but for now maybe you can create an Event Listener to listen for changes to the content fragment resources and trigger the synchronization process. Something like below to check if this works as expected.

 

@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_TOPIC + "=" + PageEvent.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=(path=/content/dam/*)"
})
public class ContentFragmentEventListener implements EventHandler {

@Reference
private ResourceResolverFactory resolverFactory;

@Override
public void handleEvent(Event event) {
PageEvent pageEvent = (PageEvent) event;
for (ResourceChange change : pageEvent.getChanges()) {
try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(null)) {
Resource resource = resolver.getResource(change.getPath());
if (resource != null && isContentFragment(resource)) {
CustomContentFragmentModel model = resource.adaptTo(CustomContentFragmentModel.class);
model.synchronizeVariations(resource.getChild("jcr:content"));
}
} catch (LoginException e) {
// Handle exception
}
}
}

private boolean isContentFragment(Resource resource) {
return resource.getResourceType().equals("dam:Asset");
}
}

kautuk_sahni
Community Manager
Community Manager
September 16, 2024

@sreenu539 Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni