Sitecore Best Practice #6: Tell me when I'm restricted

13 June 2011
Adam Najmanowicz

Sitecore best practice 6 encourages CMS AX designers to be explicit about the page workflow state.

If you really want your authors to use the on page editing feature you need to remove all the friction points they might encounter on their way. One of such is the fact that a page is locked by someone else and hence the author is not able to edit it. Sitecore is not necessarily expressing the state in the most apparent way in the ribbon UI.

Edit mode without yellow bar

To be honest, I feel this should rather become a part of the ribbon but before it does - you need to make sure your author does not feel compelled to switch to the Content Editor mode just because they cannot identify the problem with the page in the on-page-editing mode.

What is it about?

While an author uses Page Edit mode and accesses the page that is locked by another editor, there is no message or indicator that the page is locked by another user.

Why should I do it?

We don't want pages to be edited by many authors at the same time, as it could lead to incoherent page state.

Demo scenario

There are 2 authors: 'editor' and 'administrator'. 'Administrator' has locked the clients page and is editing the content. 'Editor' opens the page editor and navigates to the clients page. The panel with information about the lock should be displayed on the top of the page:

 Edit mode with yellow bar

How do I implement it?

Add a code below to your layout:

<asp:PlaceHolder ID=”phLockMessage” runat=”server” Visible=”false”>
  <table width=”100%” cellspacing=”0″ cellpadding=”3″ border=”0″ 
         style=”background: none repeat scroll 0 0 #FFFFE4; border-color: #C9C9C9 
         -moz-use-text-color; border-style: solid none; 
         border-width: 1px medium; padding: 4px 2px;”>
        <td valign=”top”>
          <img border=”0″  alt=”" class=”scEditorSectionCaptionIcon”
               style=”vertical-align: middle” />
        <td width=”100%”>
           <div style=”font: bold 8pt tahoma;”>
             <asp:Literal ID=”litLockMessage” runat=”server” />

And execute the method from the OnInit method of the layout code behind:

private void DisplayLockMessage()
    string message = String.Empty;
    Item item = Sitecore.Context.Item;
    if (item != null)
        ItemLocking locking = item.Locking;
        if (locking.IsLocked() &amp;&amp; !locking.HasLock())
            if (locking.CanUnlock())
                message = "'" + locking.GetOwner() + "' has locked this item.";
                message = "You cannot edit this item because '" + 
                          locking.GetOwner() + "' has locked it.";
    if (!String.IsNullOrEmpty(message))
        phLockMessage.Visible = true;
        litLockMessage.Text = message;

Thanks to Marek Musielak for his help with the Sitecore Best Practice #6.