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

Eric
Dec 5, 2012
  3379
(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
Shared optimizely cart between non-optimizley front end site

E-commerce ecosystems often demand a seamless shopping experience where users can shop across multiple sites using a single cart. Sharing a cart...

PuneetGarg | Dec 3, 2024

CMS Core 12.22.0 delisted from Nuget feed

We have decided to delist version 12.22.0 of the CMS Core packages from our Nuget feed, following the discovery of a bug that affects rendering of...

Magnus Rahl | Dec 3, 2024

Force Login to Optimizely DXP Environments using an Authorization Filter

When working with sites deployed to the Optimizely DXP, you may want to restrict access to the site in a particular environment to only authenticat...

Chris Sharp | Dec 2, 2024 | Syndicated blog

Video Guides: Image Generation Features in Optimizely

The AI Assistant for Optimizely now integrates seamlessly with Recraft AI, providing advanced image generation capabilities directly within your...

Luc Gosso (MVP) | Dec 1, 2024 | Syndicated blog

DAM integration new major version, performance improvements and Library Picker folder selection

As you might already have seen we have decided to delist the EPiServer.CMS.WelcomeIntegration version 1.4.0 where we introduced Graph support....

Robert Svallin | Nov 29, 2024

Adding Geolocation Personalisation to Optimizely CMS with Cloudflare

Enhance your Optimizely CMS personalisation by integrating Cloudflare's geolocation headers. Learn how my Cloudflare Geo-location Criteria package...

Andy Blyth | Nov 26, 2024 | Syndicated blog