DEV Community

Cover image for Using conventions to fine tune the editor experience in Umbraco v8
Tim Geyssens
Tim Geyssens

Posted on

4

Using conventions to fine tune the editor experience in Umbraco v8

The Umbraco backend allows you to set a start node per backend user (in both content and media) but in some cases this isn't sufficient to hide certain properties that are only of interest for power users...

Say you have the following "admin" group/tab (yes I'm using Matryoshka )

Admin tab

Where you can set that you don't want this page to be unpublished... it makes sense to have this setting as an admin but the content editors shouldn't see this one...

So with some event magic and some simple conventions we can add a bit of code that will hide the admin group/tab on all docs (if you aren't part of the admin usergroup)

using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using System.Linq;
using System;
using Umbraco.Core.Security;
using Umbraco.Web.Editors;
using Umbraco.Web;
using Umbraco.Web.Dashboards;
using Umbraco.Web.PublishedModels;
namespace MySite.Custom
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class CustomEventComposer : ComponentComposer<CustomEventComponent>
{ }
public class CustomEventComponent : IComponent
{
public void Initialize()
{
EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
}
private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Umbraco.Web.Models.ContentEditing.ContentItemDisplay> e)
{
var identity = (UmbracoBackOfficeIdentity)System.Web.HttpContext.Current.User.Identity;
var currentUSer = Current.Services.UserService.GetByProviderKey(identity.Id);
if (!currentUSer.Groups.Any(x => x.Alias == "admin"))
{
foreach (var variant in e.Model.Variants)
variant.Tabs = variant.Tabs.Where(x => x.Label != "Admin");
}
}
public void Terminate()
{
}
}
}

Main bit here is hooking into EditorModelEventManager.SendingContentModel and removing the admin tab when the current user isn't in the admin user group...

et voilà ! all admin tabs will be hidden from editors not in the admin user group.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay