For usability issues I would like to show in the Experience Editor (Sitecore 8.1 rev. 151207) if the User is currently working in the Shared or Final Layout because it is only visible in the Presentation Menu which layout is selected at the moment. Is there a easy way to get the value which is obviously available in the ribbon?
1 Answer
There is already a notification bar show in Experience Editor
mode when editing the Shared Layout of the page, but you have to select the Presentation tab before the notification will show.
In any case, you can use the IsEditAllVersionsTicked()
helper available in Sitecore.ExperienceEditor.Utils.WebUtility
to return whether Shared Layout is being edited.
Custom Editor Notification
You can create a custom editor notification to always show the current layout mode, similar to the existing notification:
using Sitecore.Diagnostics;
using Sitecore.ExperienceEditor.Utils;
using Sitecore.Globalization;
using Sitecore.Pipelines.GetPageEditorNotifications;
namespace MyProject.CMS.Custom.Pipelines
{
public class GetPageEditorNotifications : GetPageEditorNotificationsProcessor
{
public override void Process(GetPageEditorNotificationsArgs arguments)
{
Assert.ArgumentNotNull(arguments, "arguments");
if (arguments.ContextItem == null) return;
bool editingSharedVersion = WebUtility.IsEditAllVersionsTicked();
if (editingSharedVersion)
{
arguments.Notifications.Add(new PageEditorNotification(Translate.Text("You are editing the SHARED layout of this page. All the changes you make to the shared layout will be applied to all versions of this page in every language."),
PageEditorNotificationType.Warning));
}
else
{
arguments.Notifications.Add(new PageEditorNotification(Translate.Text("You are editing the FINAL layout of this page. Any changes you make to the final layout will only be applied to the current version of this page in the current language."),
PageEditorNotificationType.Information));
}
}
}
}
Patch this into your config:
<pipelines>
<getPageEditorNotifications>
<processor type="MyProject.CMS.Custom.Pipelines.GetPageEditorNotifications, MyProject.CMS.Custom" />
</getPageEditorNotifications>
</pipelines>
Removing Existing Editor Notification
You need to deal with the existing rendering information bar displayed for Shared Layout. You can do this by editing /sitecore/shell/client/Sitecore/ExperienceEditor/Commands/SelectLayout.js
and updating the canExecute method to return false:
canExecute: function (context) {
return false;
},
Alternatively, override the pipeline responsible for checking the Layout mode when switching to the tab and set the return value to false
.
<sitecore.experienceeditor.speak.requests>
<request name="ExperienceEditor.IsEditAllVersionsTicked" type="Sitecore.ExperienceEditor.Speak.Ribbon.Requests.Common.IsEditAllVersionsTicked, Sitecore.ExperienceEditor.Speak.Ribbon" />
...
</sitecore.experienceeditor.speak.requests>