What is Gutter in Sitecore?
Gutter also is known as a quick action bar, can be seen when you right click on the left bar of the content tree.Sitecore provides default gutters to know the
- Item buckets
- Cloned Items
- Personalizations
- Multivariant Tests
- My Locked Items
- Locked items
- Workflow state
- Broken links
- Missing Version
- Publishing Warnings
- Validation Rules
- Presentation overridden
In addition to these default Gutters, we can create custom Sitecore Gutters.
Steps to Create Custom Sitecore Gutter
- Create a class which inherits the GutterRenderer.
- Override the GutterIconDescriptor method in the GutterRenderer class, to set the appropriate icons to the gutter.
- Switch to core database in Sitecore interface.
- Create Custom Gutter using the /Sitecore/templates/Sitecore Client/Content editor/Gutter Renderer.
- Populate the Header and Type fields of the Gutter, Header field should contain the name you want to give to the Gutter, Type field should contain the fully qualified class name, the dll which contains the class.
- Right click on the left side of the Content tree and select your Gutter. see below screen
- The Gutter now indicates the publication status of your items
CUSTOM SITECORE GUTTER TO INDICATE PUBLISH STATUS
Never Published:
Check whether the item is present in the web database if not implies the item has never been published.
Published:
Compare the revision fields of the item in master and web databases, if found same implies that the latest revision has been published to the web.
Published to at least one target:
Check whether the item is present in any one target database if found implies the item has been published in at least on the target database.
Code & Implementation
namespace testforsitecore.Models
{
public class PublicationStatus : GutterRenderer
{
private readonly ID publishingTargetsFolderId = new ID("{D9E44555-02A6-407A-B4FC-96B9026CAADD}");
private readonly ID targetDatabaseFieldId = new ID("{39ECFD90-55D2-49D8-B513-99D15573DE41}");
protected override GutterIconDescriptor GetIconDescriptor(Item item)
{
bool existsInAll = true;
bool existsInOne = false;
// Find the publishing targets item folder
Item publishingTargetsFolder = Context.ContentDatabase.GetItem(publishingTargetsFolderId);
if (publishingTargetsFolder == null)
{
return null;
}
// Retrieve the publishing targets database names
List<string> publishingTargetsDatabases = publishingTargetsFolder.GetChildren()
.Select(x => x[targetDatabaseFieldId])
.ToList();
// Check for item existance in publishing targets
publishingTargetsDatabases.ForEach(delegate (string databaseName)
{
if (Database.GetDatabase(databaseName).GetItem(item.ID) != null)
{
existsInOne = true;
}
else
{
existsInAll = false;
}
});
// Return descriptor with tooltip and icon
string tooltip = Translate.Text("This item has not yet been published");
string icon = "People/16x16/flag_red.png";
if (existsInAll)
{
tooltip = Translate.Text("This item has been published to all targets");
icon = "People/16x16/flag_green.png";
}
else if (existsInOne)
{
tooltip = Translate.Text("This item has been published to at least one target");
icon = "People/16x16/flag_yellow.png";
}
return new GutterIconDescriptor()
{
Icon = icon,
Tooltip = tooltip,
//Click = string.Format("item:publish(id={0})", item.ID), // For Click on publish staus icon publish Item dialog box open
Click = String.Format("item:load(ID={0})", item.ID) // For Click on publish staus icon which Item is load
};
}
}
}
Conclusion:
Sitecore Gutters can be very useful since they visually indicate the state of an item which reduces the extra effort for developers. The above implementation of Sitecore Gutter to indicate the Publish Status of an item comes handy when there is no workflow configured for the items.
No comments:
Post a Comment