November Happy Hour will be moved to Thursday December 5th.

Eric
Dec 5, 2012
  3374
(2 votes)

Missing Context Menu for EPiServer Community

I have stumbled upon installations of EPiServer Community that are missing the “Context Menu”-option for Admin and Moderation. I have always thought that someone had done a mistake or that the upgrade process from EPiServer where missing to add some parts to web.config.

But today I found the solution and since I could not find any blog about the issue I thought I should share it with you.

The problem occurs when you upgrade an existing EPiServer Community installation to the latest. If you install a brand new Relate website with deployment center this will not happen. So why is these options missing.

Well what they forgot to tell us is that in the latest Relate package for CMS 6 they have added a PagePlugin!! Ler So no missing configs or other stuff… they just did not ad that to the product but to the sample project, what if we needed to ad the Context Menu to every CMS project.. would be fun right!? Blinkar

Well the code for the plugin is the following:

/// <summary>
/// Plugin to add Community item to page context menu
/// </summary>
[PagePlugIn(Description = "Adds Community item to page context menu.", DisplayName = "Community context menu",
RequireLicenseForLoad = false, SortIndex = 2000)]
public class ContextMenuPlugIn
{
/// <summary>
/// Community item name in context menu
/// </summary>
private const string _menuItemNameAdmin = "CommunityMenuItemAdmin";
private const string _menuItemNameModerate = "CommunityMenuItemModerate";

/// <summary>
/// Page paths
/// </summary>
private static readonly string _moderatePagePath = VirtualPathUtilityEx.ToAbsolute("~/EPiServerCommunity/Moderate.aspx");
private static readonly string _adminPagePath = VirtualPathUtilityEx.ToAbsolute("~/EPiServerCommunity/Admin.aspx");

/// <summary>
/// Initializes pluging.
/// </summary>
/// <param name = "optionFlag">The option flag.</param>
public static void Initialize(int optionFlag)
{
PageBase.PageSetup += PageSetupHandler;
}

/// <summary>
/// Gets a value indicating whether this plugin is enabled.
/// </summary>
/// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
private static bool Enabled
{
get
{
PlugInDescriptor descriptor = PlugInDescriptor.Load(typeof(ContextMenuPlugIn));
return descriptor != null && descriptor.Enabled;
}
}

/// <summary>
/// Handle 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 PageSetupHandler(PageBase page, PageSetupEventArgs e)
{
if (!Enabled)
{
return;
}

page.Init += PageInitHandler;
}

/// <summary>
/// Handle page Init event and adds Community menu item.
/// </summary>
/// <param name = "sender">The sender.</param>
/// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
static void PageInitHandler(object sender, EventArgs e)
{
var page = sender as PageBase;
if (page == null || page.ContextMenu == null || !page.ContextMenu.IsMenuEnabled || page.ContextMenu.Menu.Items == null)
{
return;
}
IUser currentUser = CommunitySystem.CurrentContext.DefaultSecurity.CurrentUser;
if (!page.ContextMenu.Menu.Items.Contains(_menuItemNameModerate) && CanAccessModeratorMode(currentUser))
{
var menuItem = new RightClickMenuItem(
"olle",
_moderatePagePath,
null,
"true",
VirtualPathUtilityEx.ToAbsolute("~/Templates/RelatePlus/Styles/Images/icons/CommunityModeration.png"),
RightClickMode.All);
page.ContextMenu.Menu.Add(_menuItemNameModerate, menuItem);
}

if (!page.ContextMenu.Menu.Items.Contains(_menuItemNameAdmin) && currentUser.IsCommunityAdmin())
{
var menuItem = new RightClickMenuItem(
LanguageManager.Instance.Translate("/contextmenuplugin/adminmode"),
_adminPagePath,
null,
"true",
VirtualPathUtilityEx.ToAbsolute("~/Templates/RelatePlus/Styles/Images/icons/CommunityAdmin.png"),
RightClickMode.All);

page.ContextMenu.Menu.Add(_menuItemNameAdmin, menuItem);
}
}

private static bool CanAccessModeratorMode(IUser currentUser)
{
return currentUser.IsCommunityModerator() || currentUser.IsCommunityAdmin();
}
}

 

Have a look in the Relate website and you will find the plugin as well as the images and translationfiles.

Dec 05, 2012

Comments

valdis
valdis Dec 5, 2012 07:51 PM

Great - good to know!

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog