Hi All,
We have a requirement in our project, where based on custom property at page level should lock a component from authoring. But we couldn't find way to lock at component level but we can lock at page level which is not desired functionality as other components in that page should be authorable. Please let us know if there is a solution to this problem.
Thank You,
Sham.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @sham2348
You can achieve a similar kind of functionality by manipulating the component edit bar. though you can't lock and unlock component however you can remove edit option from component edit toolbar on the checkbox. you can use ComponentContext and Toolbar API to remove edit option from the component edit toolbar.
you have to perform below steps.
1. Add a node cq:editConfig(jcr:primaryType - cq:EditConfig) and all actions. ComponentContext takes your component's local cq:editConfig node.
2. In PostConstruct method get pageProperties and required property. Get Toolbar using ComponentContext and remove edit (or any other) other from toolbar.
boolean hideComp=currentPage.getProperties().get("hideComponent",false);
if(hideComp) {
ComponentContext componentContext = WCMUtils.getComponentContext(slingRequest);
Toolbar componentToolbar = componentContext.getEditContext().getEditConfig().getToolbar();
componentToolbar.remove(EditAction.EDIT);
}
@sham2348 you can do by customizing cq:editconfig. Please refer to below article for reference..
https://blogs.perficient.com/2023/01/31/customize-your-aem-component-toolbar/
Hi @sham2348
You can achieve a similar kind of functionality by manipulating the component edit bar. though you can't lock and unlock component however you can remove edit option from component edit toolbar on the checkbox. you can use ComponentContext and Toolbar API to remove edit option from the component edit toolbar.
you have to perform below steps.
1. Add a node cq:editConfig(jcr:primaryType - cq:EditConfig) and all actions. ComponentContext takes your component's local cq:editConfig node.
2. In PostConstruct method get pageProperties and required property. Get Toolbar using ComponentContext and remove edit (or any other) other from toolbar.
boolean hideComp=currentPage.getProperties().get("hideComponent",false);
if(hideComp) {
ComponentContext componentContext = WCMUtils.getComponentContext(slingRequest);
Toolbar componentToolbar = componentContext.getEditContext().getEditConfig().getToolbar();
componentToolbar.remove(EditAction.EDIT);
}
Views
Likes
Replies