Skip to content

Instantly share code, notes, and snippets.

@tompipe
Last active October 6, 2021 16:59
Show Gist options
  • Save tompipe/70df652479d93733a17491733219b35c to your computer and use it in GitHub Desktop.
Save tompipe/70df652479d93733a17491733219b35c to your computer and use it in GitHub Desktop.
Workaround for bug in BlockListPropertyEditor https://github.com/umbraco/Umbraco-CMS/issues/10910
using System;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Runtime;
using Umbraco.Core.Services;
using Umbraco.Web.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[ComposeAfter(typeof(CoreInitialComposer))]
public class BlockListPropertyEditorTempFixComposer : IUserComposer
{
public void Compose(Composition composition)
{
// bug was introduced in 8.15, doesn't affect earlier versions
// https://github.com/umbraco/Umbraco-CMS/issues/10910
if (UmbracoVersion.Current <= new Version(8, 15))
return;
// bug was fixed in 8.15.3
if (UmbracoVersion.Current >= new Version(8, 15, 3))
return;
// exclude the BlockListPropertyEditor with the bug
composition.DataEditors().Exclude<BlockListPropertyEditor>();
// and re-register it with a workaround
composition.DataEditors().Add<BlockListPropertyEditorTempFix>();
}
}
[DataEditor(
Constants.PropertyEditors.Aliases.BlockList,
"Block List",
"blocklist",
ValueType = ValueTypes.Json,
Group = Constants.PropertyEditors.Groups.Lists,
Icon = "icon-thumbnail-list")]
[HideFromTypeFinder]
public class BlockListPropertyEditorTempFix : BlockListPropertyEditor, IDataEditor
{
public BlockListPropertyEditorTempFix(ILogger logger, Lazy<PropertyEditorCollection> propertyEditors, IDataTypeService dataTypeService, IContentTypeService contentTypeService, ILocalizedTextService localizedTextService)
: base(logger, propertyEditors, dataTypeService, contentTypeService, localizedTextService)
{
}
IDataValueEditor IDataEditor.GetValueEditor()
{
// base method caches the editor, but inadvertently caches doctypes too.
// call CreateValueEditor directly to prevent the cached _reusableEditor from being used
// https://github.com/umbraco/Umbraco-CMS/issues/10910
return CreateValueEditor();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment