Last active
October 6, 2021 16:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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