November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
1. The menu is added as a page extension by the constructor of the TemplatePage class (http://sdk.episerver.com/library/cms6/html/T_EPiServer_Web_PageExtensions_ContextMenu.htm). This will add a web control that adds the items and does the rendering. You can access the plug-in using the property ContextMenu on any class that inherits from PageBase.
2. The menu appears for users that have either publish access rights to the current page or access to the backing UI (edit, admin etc).
3. I don't think that this is publicly documented but I guess you could add items to the RightClickMenu class that can be accessed by the Menu property on ContextMenu.
4. No idea here...
Regards
Linus Ekström
You can add or remove context menu items. Please look at this: http://sdk.episerver.com/library/cms5/Developers%20Guide/How%20To/Add%20and%20Remove%20Right-click%20Menu%20Items.htm
Here is sample code to add one custom item to context menu. You can easily extend it to add/remove/disable few items. This plug-in can be enabled/disabled in CMS Admin mode / Confug / Plug-in Manager.
/// <summary>
/// Sample plug-in to add cutom item to context menu
/// </summary>
[PagePlugIn]
public class CustomContextMenuPlugIn
{
/// <summary>
/// Initializes plug-in with the specified option flag.
/// </summary>
/// <param name="optionFlag">The option flag.</param>
public static void Initialize(int optionFlag)
{
PageBase.PageSetup += new PageSetupEventHandler(OnPageSetup);
}
/// <summary>
/// Gets a value indicating whether this <see cref="CustomContextMenuPlugIn"/> is enabled.
/// </summary>
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
private static bool Enabled
{
get
{
PlugInDescriptor descriptor = PlugInDescriptor.Load(typeof(CustomContextMenuPlugIn));
return descriptor != null && descriptor.Enabled;
}
}
/// <summary>
/// Called on page setup event.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="e">The <see cref="EPiServer.PageSetupEventArgs"/> instance containing the event data.</param>
public static void OnPageSetup(PageBase page, PageSetupEventArgs e)
{
if (!Enabled)
{
return;
}
// TODO: check security here...
page.Init += new EventHandler(OnPageInit);
}
/// <summary>
/// Called on page init event.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
static void OnPageInit(object sender, EventArgs e)
{
var menuItemName = "CustomMenuItem";
PageBase page = sender as PageBase;
if (page == null || page.ContextMenu == null || !page.ContextMenu.IsMenuEnabled)
{
return;
}
if (page.ContextMenu.Menu.Items == null || page.ContextMenu.Menu.Items.Contains(menuItemName))
{
return;
}
var menuItem = page.ContextMenu.CreateMenuItem(
"Menu item title",
UriSupport.ResolveUrlBySettings("~/your/path"),
"alert('Hello menu item!')",
"true",
UriSupport.ResolveUrlBySettings("~/Resources/CustomMenuIcon.gif"),
RightClickMode.All);
page.ContextMenu.Menu.Add(menuItemName, menuItem);
}
}
I'd like to add a button on a page (for logged in users with correct access rights) to activate on-page edit, the same functionality that exists today in the right click edit/admin menu. I can't quite make it work and thus I have some questions:
Looking forward to hear from you!
/Kristoffer