Unfortunately RenderNotifications
method of WebEditRibbonForm
class contains check:
if (WebUtil.GetQueryString("mode") != "edit")
return;
The simplest solution would be to override WebEditRibbonForm
, replace CodeBeside
from the original WebEditorRibbonForm
to your custom class in sitecore\shell\Applications\WebEdit\WebEditRibbon.aspx
file and write few methods like below to make sure that Sitecore renders notifications in preview
mode as well:
public class ExtendedWebEditorRibbonForm : WebEditRibbonForm
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ItemUri queryString = ItemUri.ParseQueryString();
if (!Context.ClientPage.IsEvent)
{
Item item = Database.GetItem(queryString);
if (item != null)
{
RenderNotifications(item);
}
}
}
private void RenderNotifications(Item item)
{
Assert.ArgumentNotNull(item, nameof(item));
// in preview mode we do same what Sitecore does in edit mode
if (WebUtil.GetQueryString("mode") != "preview")
return;
List<PageEditorNotification> editorNotifications = ItemUtility.GetPageEditorNotifications(item);
if (editorNotifications.Count == 0)
{
Notifications.Visible = false;
}
else
{
HtmlTextWriter output = new HtmlTextWriter(new StringWriter());
int count = editorNotifications.Count;
for (int index = 0; index < count; ++index)
{
PageEditorNotification notification = editorNotifications[index];
string empty = string.Empty;
if (index == 0)
empty += " First";
if (index == count - 1)
empty += " Last";
RenderNotification(output, notification, empty);
}
Notifications.InnerHtml = output.InnerWriter.ToString();
}
}
private static void RenderNotification(HtmlTextWriter output, PageEditorNotification notification, string marker)
{
Assert.ArgumentNotNull(output, nameof(output));
Assert.ArgumentNotNull(notification, nameof(notification));
Assert.ArgumentNotNull(marker, nameof(marker));
string str = Themes.MapTheme(notification.Icon ?? GetNotificationIcon(notification.Type));
output.Write("<div class=\"scPageEditorNotification {0}{1}\">", notification.Type, marker);
output.Write("<img class=\"Icon\" src=\"{0}\"/>", str);
output.Write("<div class=\"Description\">{0}</div>", notification.Description);
foreach (PageEditorNotificationOption option in notification.Options)
output.Write("<a onclick=\"javascript: return scForm.postEvent(this, event, '{0}')\" href=\"#\" class=\"OptionTitle\">{1}</a>", option.Command, option.Title);
output.Write("<br style=\"clear: both\"/>");
output.Write("</div>");
}
private static string GetNotificationIcon(PageEditorNotificationType notificationType)
{
switch (notificationType)
{
case PageEditorNotificationType.Error:
return "Custom/16x16/error.png";
case PageEditorNotificationType.Information:
return "Custom/16x16/info.png";
default:
return "Custom/16x16/warning.png";
}
}
}