Within page editor you can setup custom info bars to feedback more info to your users using page editor notifications. An example of this is:
Custom notifications can be patched into the app via:
1 2 3 |
<getPageEditorNotifications> <processor type="###.SitecoreCustom.Pipelines.GetPreviewNotifications.GetVersionsDoesntExistNotification, ###.SitecoreCustom" /> </getPageEditorNotifications> |
Where your custom code implements:
1 2 3 4 5 6 7 8 9 10 |
namespace ###.SitecoreCustom.Pipelines.GetPreviewNotifications { public class GetVersionsDoesntExistNotification : GetPageEditorNotificationsProcessor { public override void Process(GetPageEditorNotificationsArgs arguments) { //custom implementation } } } |
In this example, I based my implementation on Sitecore.Pipelines.GetPageEditorNotifications.GetWorkflowNotification, Sitecore.Kernel
In order to get notifications showing in preview you need to customize things slightly. The toolbar shown in preview and page editor is the WebEditRibbonForm. This is linked into the ui via:
/sitecore/shell/applications/webedit/webeditribbon.aspx
The line that ties the class and the aspx together is:
1 |
<sc:CodeBeside runat="server" Type="###.SitecoreCustom.Shell.Applications.WebEdit.PreviewWebEditRibbonForm,###.SitecoreCustom"/> |
Using reflector I extracted out the existing implementation of WebEditRibbonForm and extended to work with preview:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Web.UI; using Sitecore; using Sitecore.Data; using Sitecore.Data.Items; using Sitecore.Diagnostics; using Sitecore.Pipelines; using Sitecore.Pipelines.GetPageEditorNotifications; using Sitecore.Shell.Applications.WebEdit; using Sitecore.Web; namespace ###.SitecoreCustom.Shell.Applications.WebEdit { public class PreviewWebEditRibbonForm : WebEditRibbonForm { protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Context.ClientPage.IsEvent) { } else { ItemUri uri = ItemUri.ParseQueryString(); Assert.IsNotNull(uri, typeof(ItemUri)); Item item = Database.GetItem(uri); Assert.IsNotNull(item, typeof(Item)); RenderPreviewNotifications(item); } } private void RenderPreviewNotifications(Item item) { Assert.ArgumentNotNull(item, "item"); if (WebUtil.GetQueryString("mode") == "preview") { GetPageEditorNotificationsArgs args = new GetPageEditorNotificationsArgs(item); CorePipeline.Run("getPreviewNotifications", args); List<PageEditorNotification> notifications = args.Notifications; if (notifications.Count == 0) { Notifications.Visible = false; } else { //custom replacement of GroupNotifications(notifications); MethodInfo groupNotifications = typeof(WebEditRibbonForm).GetMethod("GroupNotifications", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (groupNotifications != null) { notifications = (List<PageEditorNotification>) groupNotifications.Invoke(null, new object[] {notifications}); } HtmlTextWriter output = new HtmlTextWriter(new StringWriter()); int count = notifications.Count; for (int i = 0; i < count; i++) { PageEditorNotification notification = notifications[i]; string marker = string.Empty; if (i == 0) { marker = marker + " First"; } if (i == (count - 1)) { marker = marker + " Last"; } //custom replacement of RenderNotification(output, notification, marker); // to get around the fact its private static MethodInfo renderNotification = typeof(WebEditRibbonForm).GetMethod("RenderNotification", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (renderNotification != null) { renderNotification.Invoke(null, new object[] {output, notification, marker}); } } Notifications.InnerHtml = output.InnerWriter.ToString(); } } } } } |
An interesting challenge is the need to use reflection to call private static methods on the base class:
1 2 3 4 5 6 7 8 9 |
//custom replacement of RenderNotification(output, notification, marker); // to get around the fact its private static MethodInfo renderNotification = typeof(WebEditRibbonForm).GetMethod("RenderNotification", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (renderNotification != null) { renderNotification.Invoke(null, new object[] {output, notification, marker}); } |
The only thing you now need to do is patch in your own custom pipeline:
1 2 3 |
<getPreviewNotifications> <processor type="###.SitecoreCustom.Pipelines.GetPreviewNotifications.GetVersionsDoesntExistNotification, ###.SitecoreCustom" /> </getPreviewNotifications> |
know how to do this in Sitecore 8.1?