Try our conversational search powered by Generative AI!

Eric
Dec 5, 2012
  3298
(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
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024

The Experimentation Process

This blog is part of the series -   Unlocking the Power of Experimentation: A Marketer's Insight. Welcome back, to another insightful journey into...

Holly Quilter | May 16, 2024

Azure AI Language – Sentiment Analysis in Optimizely CMS

In the following article, I showcase how sentiment analysis, which is part of the Azure AI Language service, can be used to detect the sentiment of...

Anil Patel | May 15, 2024 | Syndicated blog