Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created November 24, 2020 23:01
Show Gist options
  • Save nathanwoulfe/fa5cb60a9f45913cede864f41fe8e138 to your computer and use it in GitHub Desktop.
Save nathanwoulfe/fa5cb60a9f45913cede864f41fe8e138 to your computer and use it in GitHub Desktop.
Minimal component for testing
using System;
using System.Linq;
using System.Web.Http.Filters;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace Foo.Bar.AppCode
{
public class TestContentEventsComponent : IComponent
{
public void Initialize()
{
EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
}
public void Terminate()
{
EditorModelEventManager.SendingContentModel -= EditorModelEventManager_SendingContentModel;
}
/// <summary>
/// Remove the workflow app if the node is exclude or has no content app
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void EditorModelEventManager_SendingContentModel(HttpActionExecutedContext sender, EditorModelEventArgs<ContentItemDisplay> e)
{
try
{
var apps = e.Model.ContentApps;
// on 1.4.3, this is the line throwing the error
if (!e.Model.IsElement && apps != null && apps.Any(a => a.Alias == "umbContent"))
{
return;
}
}
catch(Exception ex)
{
Current.Logger.Error(typeof(TestContentEventsComponent), ex, ex.Message);
}
}
}
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class TestComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components()
.Append<TestContentEventsComponent>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment