Component level lock in the page | Community
Skip to main content
May 23, 2023
Solved

Component level lock in the page

  • May 23, 2023
  • 2 replies
  • 844 views

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.

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 sunil_kumar_

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

 

2 replies

Shashi_Mulugu
Community Advisor
Community Advisor
May 23, 2023

@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/

sunil_kumar_
sunil_kumar_Accepted solution
Level 5
May 24, 2023

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