Whenever you create an AEM component that can be authored, it will normally display an edit toolbar that allows an author to configure it. The toolbar typically consists of edit actions such as Edit, Cut, Copy, Paste, and Delete. However, there may be times when you want to limit those options. What if you only want to display certain edit actions based on custom conditions such as who the user is or what group the user belongs to? What if you want to restrict certain users or groups from even authoring a component while other types of users are allowed to? How do you dynamically control that based on run-time conditions?
Access control lists are only effective for the Edit action but are not applicable for the others like Cut, Copy, Paste, or Delete. Render conditions are not even applicable for the component’s toolbar.
One solution is through usage of the ComponentContext and EditContext objects within the Sling model of your component. This allows you to include the required logic needed for a specific component. In this blog, I will explain how to enhance your component based on certain criteria to:
Dynamically manipulate the edit actions of the edit toolbar for a targeted component
Dynamically disable the edit toolbar for a targeted component
How to display appropriate edit actions based on author’s user group
Dynamically manipulate the component’s edit actions by first defining the cq:editConfig node with the default actions desired for the component when it’s not necessary to be changed.