Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Eric
Dec 5, 2012
  3287
(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
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog