Eric
Dec 5, 2012
  3324
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024