Skip to content

Instantly share code, notes, and snippets.

@prjseal
Created January 18, 2022 09:19
Show Gist options
  • Save prjseal/2748f369ca659be5ff1fc9b8db992440 to your computer and use it in GitHub Desktop.
Save prjseal/2748f369ca659be5ff1fc9b8db992440 to your computer and use it in GitHub Desktop.
Hide Properties in Umbraco 8
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web.Editors;
namespace CodeShare.Core.Composing
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class EditorModelEventsComposer : ComponentComposer<EditorModelEventsComponent>
{
}
public class EditorModelEventsComponent : IComponent
{
public void Initialize()
{
EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
}
public void Terminate()
{
EditorModelEventManager.SendingContentModel -= EditorModelEventManager_SendingContentModel;
}
private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Umbraco.Web.Models.ContentEditing.ContentItemDisplay> e)
{
if (e.Model.ContentTypeAlias != "pageTypeAlias") return;
foreach (var variant in e.Model.Variants)
{
foreach (var tab in variant.Tabs)
{
tab.Properties = tab.Properties.Where(x => x.Alias != "propertyAlias");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment