Expand my Community achievements bar.

SOLVED

Component level lock in the page

Avatar

Level 1

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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. 
Screenshot 2023-05-24 at 1.09.04 AM.png

 

Screenshot 2023-05-24 at 1.09.15 AM.png

 

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);
}

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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. 
Screenshot 2023-05-24 at 1.09.04 AM.png

 

Screenshot 2023-05-24 at 1.09.15 AM.png

 

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);
}