Skip to content

Instantly share code, notes, and snippets.

@hartviglarsen
Created April 4, 2019 18:47
Show Gist options
  • Select an option

  • Save hartviglarsen/29cf46d95c9f0cf4e5ca8169d02d94a2 to your computer and use it in GitHub Desktop.

Select an option

Save hartviglarsen/29cf46d95c9f0cf4e5ca8169d02d94a2 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.PublishedModels;
namespace MvcCourse.Core.Components
{
public class ProductsComponent : 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)
{
if (e.Model.ContentTypeAlias != Products.ModelTypeAlias)
{
return;
}
foreach (var variant in e.Model.Variants)
{
var tab = variant.Tabs.FirstOrDefault(t => t.Label.InvariantContains("shop"));
if (tab != null)
{
tab.Properties = tab.Properties
.Where(p => p.Alias != Products.GetModelPropertyType(x => x.DefaultCurrency).Alias);
}
}
}
public void Terminate() { }
}
}
using MvcCourse.Core.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Composing;
namespace MvcCourse.Core.Composers
{
public class ProductsComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<ProductsComponent>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment