Files
Umbraco-CMS/src/Umbraco.Infrastructure/PropertyEditors/CheckBoxListPropertyEditor.cs
Andy Butland 5fc12ec36e Support persistence of unrestricted selections from the check box list (#19856)
* Use unrestricted text field when creating data types based on the CheckboxList property editor.
Initialize default checkbox list data type with the unrestricted text field for storage on new installs.
Migrate existing data type and property data.

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Correctly use constant.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-05 13:19:25 +02:00

41 lines
1.6 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Serialization;
namespace Umbraco.Cms.Core.PropertyEditors;
/// <summary>
/// A property editor to allow multiple checkbox selection of pre-defined items.
/// </summary>
[DataEditor(
Constants.PropertyEditors.Aliases.CheckBoxList,
ValueType = ValueTypes.Text, // We use the Text value type to ensure we don't run out of storage space in the database field with large lists with multiple values selected.
ValueEditorIsReusable = true)]
public class CheckBoxListPropertyEditor : DataEditor
{
private readonly IIOHelper _ioHelper;
private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer;
/// <summary>
/// The constructor will setup the property editor based on the attribute if one is found
/// </summary>
public CheckBoxListPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer)
: base(dataValueEditorFactory)
{
_ioHelper = ioHelper;
_configurationEditorJsonSerializer = configurationEditorJsonSerializer;
SupportsReadOnly = true;
}
/// <inheritdoc />
protected override IConfigurationEditor CreateConfigurationEditor() =>
new ValueListConfigurationEditor(_ioHelper, _configurationEditorJsonSerializer);
/// <inheritdoc />
protected override IDataValueEditor CreateValueEditor() =>
DataValueEditorFactory.Create<MultipleValueEditor>(Attribute!);
}