Thursday 31 January 2019

Check SiteCore Items Publish or Not using GutterRender






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

  1. Create a class which inherits the GutterRenderer.
  2. Override the GutterIconDescriptor method in the GutterRenderer class, to set the appropriate icons to the gutter.
  3. Switch to core database in Sitecore interface.
  4. Create Custom Gutter using the /Sitecore/templates/Sitecore Client/Content editor/Gutter Renderer.
  5. 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.


  6. Right click on the left side of the Content tree and select your Gutter. see below screen 


  7. 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.


Wednesday 30 January 2019

How to hide the "publish subitems" option in the publish dialog box.


When publishing the item given two option "Publish subitem" or "publish related items". When checkbox checked these option then publish item of the subitems or related items are published. If you want to hide these options then follow the below steps.

Hide the Publish SubItem option in the publish dialog box.





Steps:

  1. Copy Publish.xml file from "sitecore\shell\Applications\Dialogs\Publish" folder to "sitecore\shell\override" folder, so that you don’t mess up original file in case if you want to revert back your changes, just delete the newly copied file of "sitecore\shell\override" folder.
  2. Find XML code for control in Publish.xml file, something similar to below:

    <Border ID="PublishChildrenPane">
                  <br /><Checkbox ID="PublishChildren" Header="Publish subitems"/>
                   <br />
                   <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
     </Border>
  3. Add Visible = "False" attribute to border control like below: e.g.

              <Border ID="PublishChildrenPane" Visible = "False">
                         <br /><Checkbox ID="PublishChildren" Header="Publish subitems"/>
                          <br />
                           <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
              </Border>
  4. For default checked or unchecked you can add attribute IsChecked = "True" to the checkbox

    <Border ID="PublishChildrenPane" Visible = "False">
     <br />
    <Checkbox ID="PublishChildren" Header="Publish subitems" IsChecked = "True"/
       <br />
    <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
    </Border>
  5. Now you see the dilog box like this. No have to option to checked  "publish subitems"  or  "Publish related items".






Tuesday 8 January 2019

How to Manage Desktop Shortcuts in Sitecore CMS

Creating a Shortcut

To create a shortcut, right-click on the desktop and select “Create Shortcut”.
In the “Link” section that opens, click the “Browse” button.
This will open the “Insert Item”.
Select the desired item in the content tree and click the “Insert” button to return to the “Link” section.
Be sure to give the shortcut a name (HomeData), and custom icon to make it recognizable.
When finished, click “OK” to create the new shortcut.

Editing a Shortcut

To edit an existing shortcut, right click on the shortcut and select “Properties”.
This will reopen the “Link” modal.
Make any necessary changes to the shortcut and click “OK” when finished.
For Example, name: HomeContent.

Deleting a Shortcut

To delete an existing shortcut, right click on the shortcut and select “Remove Shortcut”.

A confirmation dialogue will appear. Click “OK” to delete the shortcut.

Desktop image change.

Scenario 1: 
Right-click on the desktop and select "Properties".
Select Background which is you want and clicks on the "Apply" button.
Scenario 2 :
Go to control panel and click on "Change desktop background" in  "MY SETTINGS" section.
Select Background which is you want and clicks on the "Apply" button.




Sitecore Publishing Service 7.0 Installation Guide

  About the Publishing Service module The Publishing Service module is an optional replacement for the existing Sitecore publishing methods....