Is there any way to enable content editor gutter items by default, ideally for specific roles? I see the gutter items in the core database but none of the fields seem to be indicative of enabling or disabling a given item. Just hiding it.
1 Answer
I don't think that Sitecore provides a setting in Core DB or config entries to enable the "Gutter Items" by default. But You can write your own processors/pipeline to enable all/required gutter menu when the user logging into Sitecore.
Whenever you select/change the gutter items in the Content Editor it will be updated in the Sitecore registry "/Current_User/Content Editor/Gutter Renderers". So you just need to add the gutter item ID which you can see from the folder /sitecore/content/Applications/Content Editor/Gutters in Core DB to the Sitecore registry /Current_User/Content Editor/Gutter Renderers. This will enable the specific gutter menu for the user by default once logged-in.
For Ex - If you want to enable the menu "Cloned Items" you need to add the item "/sitecore/content/Applications/Content Editor/Gutters/Clones" Id to the Sitecore Registry "/Current_User/Content Editor/Gutter Renderers".
May be something like the below:
Just injected the below processor in the "loggedin" group of processors and checking for the Item [/sitecore/content/Applications/Content Editor/Gutters/Clones] id in the existing registry setting, if it's not available then adding it to the registry to make the "Cloned Items" checked for the user all the time.
class CustomLoggedIn : LoggedInProcessor
{
public override void Process(LoggedInArgs args)
{
string gutterItemIDString = "{4DA1472A-9CE8-4709-963D-5DE65FE2885A}";
ListString existingsettings = new ListString(Registry.GetString("/Current_User/Content Editor/Gutter Renderers"));
if (!existingsettings.Contains(gutterItemIDString))
{
existingsettings.Add(gutterItemIDString);
Registry.SetString("/Current_User/Content Editor/Gutter Renderers", existingsettings.ToString());
}
}
}
-
Thanks, I'll try this out. But can I activate this processor only for users who have a specific role assigned to them? May 6, 2019 at 20:47
-
I hope the user context will be available if you add this processor at the end of loggedin, so you can check the user role using Sitecore.Context.User.IsInRole() and activate the gutter items. May 7, 2019 at 1:09
-
I'm trying to implement this - first of all you need a <> for the List<String>'s, but also, intellisense is complaining that I'm trying to convert an int to a string? May 7, 2019 at 18:05
-
Above code should work if you have the usings, using Sitecore.Pipelines.LoggedIn; using Sitecore.Text; using Sitecore.Web.UI.HtmlControls; Could you please post your code here if it fails for some reason. May 7, 2019 at 19:00
-
I thought ListString was supposed to be List<String> so changed it and that's why I was getting that error. May 7, 2019 at 19:31