Everytime you create an AEM part that may be authored, it is going to usually show an edit toolbar that enables an creator to configure it. The toolbar sometimes consists of edit actions corresponding to Edit, Reduce, Copy, Paste, and Delete. Nonetheless, there could also be instances whenever you need to restrict these choices. What in the event you solely need to show sure edit actions based mostly on customized circumstances corresponding to who the consumer is or what group the consumer belongs to? What if you wish to prohibit sure customers or teams from even authoring a part whereas different kinds of customers are allowed to? How do you dynamically management that based mostly on run-time circumstances?
Entry management lists are solely efficient for the Edit motion however usually are not relevant for the others like Reduce, Copy, Paste, or Delete. Render circumstances usually are not even relevant for the part’s toolbar.
One answer is thru utilization of the ComponentContext and EditContext objects throughout the Sling mannequin of your part. This lets you embrace the required logic wanted for a selected part. On this weblog, I’ll clarify the way to improve your part based mostly on sure standards to:
Dynamically manipulate the edit actions of the edit toolbar for a focused part
Dynamically disable the edit toolbar for a focused part
Learn how to show applicable edit actions based mostly on creator’s consumer group
Dynamically manipulate the part’s edit actions by first defining the cq:editConfig node with the default actions desired for the part when it’s not essential to be modified. For instance, you may outline typical edit actions for Edit, Copy, Reduce, Delete as such:
Subsequent, you have to to replace your part’s Sling mannequin init() methodology to incorporate:
The customized logic that specifies the circumstances that requires altering the part’s edit actions
The edit actions that should be added/eliminated when the above circumstances are met
To get a reference of the edit toolbar, you’ll use the ComponentContext to get a deal with of the Toolbar of the EditConfig object. After getting that, you may add or take away any edit actions on that toolbar.
Within the instance under, the situation to examine for is whether or not the logged in creator ought to have entry to all of the edit actions allowed for a part or only a subset of the default actions. Particularly, if the creator isn’t within the desired consumer group, they will be unable to see the Delete or Insert buttons within the edit toolbar. Likewise, solely authors throughout the directors teams are allowed to see all of the edit choices.
Lastly, make sure that your Sightly part is utilizing your Sling mannequin. Because you’ve added all the mandatory logic in your init() methodology, there’s no want for every other invocations of the Sling mannequin. Merely utilizing the mannequin will do the trick as proven under.
Fully take away edit toolbar based mostly on creator’s consumer group
Fully take away a part’s edit toolbar from view based mostly on particular circumstances by setting the Ornament tag (AKA cq:noDecoration property) accordingly. The Ornament tag will wrap a generated HTML aspect round a part that’s used for:
Modifying the part
Making use of CSS lessons that present format data and styling data
The Ornament tag is enabled for all elements by default. Extra particulars on this tag might be discovered within the Adobe documentation.
Now for this use case, it isn’t essential to outline the cq:editConfig node to your part. It is vitally much like the earlier instance however you merely must retrieve the ComponentContext after which set the ornament property at any time when your customized circumstances are met. As soon as once more, you may add this logic in your part’s Sling mannequin’s init() methodology. Higher but, add it to a utility class that may be referenced by any part. Under is an instance based mostly off of an in depth weblog written by Arun Patidar with some minor tweaks.
As within the earlier use case, merely utilizing the Sling mannequin in your Sightly part is all that’s wanted to cover the edit toolbar from authors who usually are not within the desired consumer teams.
We’re Your Go-to AEM Associate
I hope the above examples enable you to dynamically modify your part’s edit actions and toolbar based mostly in your desired circumstances. If you happen to want help to your AEM undertaking, join with us! We’re licensed by Adobe for our confirmed capabilities, and we maintain an Adobe Expertise Supervisor specialization (amongst others).