Files
Umbraco-CMS/src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs

55 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2019-10-28 13:25:05 +01:00
using Umbraco.Core;
2019-12-04 14:03:39 +01:00
using Umbraco.Core.IO;
2017-05-12 14:49:44 +02:00
using Umbraco.Core.Logging;
2019-10-28 13:25:05 +01:00
using Umbraco.Core.Models.Editors;
2017-05-12 14:49:44 +02:00
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
2017-05-12 14:49:44 +02:00
namespace Umbraco.Web.PropertyEditors
{
[DataEditor(
Constants.PropertyEditors.Aliases.MultiNodeTreePicker,
"Multinode Treepicker",
"contentpicker",
ValueType = ValueTypes.Text,
Group = Constants.PropertyEditors.Groups.Pickers,
Icon = "icon-page-add")]
2018-03-19 18:39:34 +01:00
public class MultiNodeTreePickerPropertyEditor : DataEditor
2017-05-12 14:49:44 +02:00
{
2019-12-04 14:03:39 +01:00
private readonly IIOHelper _ioHelper;
public MultiNodeTreePickerPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IIOHelper ioHelper, IShortStringHelper shortStringHelper)
: base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper)
2019-12-04 14:03:39 +01:00
{
_ioHelper = ioHelper;
}
2017-05-12 14:49:44 +02:00
2019-12-04 14:03:39 +01:00
protected override IConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor(_ioHelper);
2019-10-28 13:25:05 +01:00
protected override IDataValueEditor CreateValueEditor() => new MultiNodeTreePickerPropertyValueEditor(DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, Attribute);
2019-10-28 13:25:05 +01:00
public class MultiNodeTreePickerPropertyValueEditor : DataValueEditor, IDataValueReference
2019-10-28 13:25:05 +01:00
{
public MultiNodeTreePickerPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, DataEditorAttribute attribute)
: base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute)
2019-10-28 13:25:05 +01:00
{
}
public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var asString = value == null ? string.Empty : value is string str ? str : value.ToString();
var udiPaths = asString.Split(',');
foreach (var udiPath in udiPaths)
if (UdiParser.TryParse(udiPath, out var udi))
yield return new UmbracoEntityReference(udi);
}
2019-10-28 13:25:05 +01:00
}
2017-05-12 14:49:44 +02:00
}
2019-10-28 13:25:05 +01:00
2017-07-20 11:21:28 +02:00
}