Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Umbraco.Tests/Published/NestedContentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
Expand All @@ -33,7 +34,7 @@ public class NestedContentTests
var proflog = new ProfilingLogger(logger, profiler);

PropertyEditorCollection editors = null;
var editor = new NestedContentPropertyEditor(logger, new Lazy<PropertyEditorCollection>(() => editors));
var editor = new NestedContentPropertyEditor(logger, new Lazy<PropertyEditorCollection>(() => editors), Mock.Of<IDataTypeService>());
editors = new PropertyEditorCollection(new DataEditorCollection(new DataEditor[] { editor }));

var dataType1 = new DataType(editor)
Expand Down
20 changes: 20 additions & 0 deletions src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.PropertyEditors;

namespace Umbraco.Web.PropertyEditors
Expand All @@ -25,5 +26,24 @@ protected override IConfigurationEditor CreateConfigurationEditor()
{
return new ContentPickerConfigurationEditor();
}

protected override IDataValueEditor CreateValueEditor() => new ContentPickerPropertyValueEditor(Attribute);

internal class ContentPickerPropertyValueEditor : DataValueEditor, IDataValueReference
{
public ContentPickerPropertyValueEditor(DataEditorAttribute attribute) : base(attribute)
{
}

public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var asString = value is string str ? str : value?.ToString();

if (string.IsNullOrEmpty(asString)) yield break;

if (Udi.TryParse(asString, out var udi))
yield return new UmbracoEntityReference(udi);
}
}
}
}
59 changes: 49 additions & 10 deletions src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ public class GridPropertyEditor : DataEditor
private IUmbracoContextAccessor _umbracoContextAccessor;
private readonly HtmlImageSourceParser _imageSourceParser;
private readonly RichTextEditorPastedImages _pastedImages;
private readonly HtmlLocalLinkParser _localLinkParser;

public GridPropertyEditor(ILogger logger, IUmbracoContextAccessor umbracoContextAccessor, HtmlImageSourceParser imageSourceParser, RichTextEditorPastedImages pastedImages)
public GridPropertyEditor(ILogger logger,
IUmbracoContextAccessor umbracoContextAccessor,
HtmlImageSourceParser imageSourceParser,
RichTextEditorPastedImages pastedImages,
HtmlLocalLinkParser localLinkParser)
: base(logger)
{
_umbracoContextAccessor = umbracoContextAccessor;
_imageSourceParser = imageSourceParser;
_pastedImages = pastedImages;
_localLinkParser = localLinkParser;
}

public override IPropertyIndexValueFactory PropertyIndexValueFactory => new GridPropertyIndexValueFactory();
Expand All @@ -44,22 +50,30 @@ public GridPropertyEditor(ILogger logger, IUmbracoContextAccessor umbracoContext
/// Overridden to ensure that the value is validated
/// </summary>
/// <returns></returns>
protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _umbracoContextAccessor, _imageSourceParser, _pastedImages);
protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _umbracoContextAccessor, _imageSourceParser, _pastedImages, _localLinkParser);

protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor();

internal class GridPropertyValueEditor : DataValueEditor
internal class GridPropertyValueEditor : DataValueEditor, IDataValueReference
{
private IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly HtmlImageSourceParser _imageSourceParser;
private readonly RichTextEditorPastedImages _pastedImages;

public GridPropertyValueEditor(DataEditorAttribute attribute, IUmbracoContextAccessor umbracoContextAccessor, HtmlImageSourceParser imageSourceParser, RichTextEditorPastedImages pastedImages)
private readonly RichTextPropertyEditor.RichTextPropertyValueEditor _richTextPropertyValueEditor;
private readonly MediaPickerPropertyEditor.MediaPickerPropertyValueEditor _mediaPickerPropertyValueEditor;

public GridPropertyValueEditor(DataEditorAttribute attribute,
IUmbracoContextAccessor umbracoContextAccessor,
HtmlImageSourceParser imageSourceParser,
RichTextEditorPastedImages pastedImages,
HtmlLocalLinkParser localLinkParser)
: base(attribute)
{
_umbracoContextAccessor = umbracoContextAccessor;
_imageSourceParser = imageSourceParser;
_pastedImages = pastedImages;
_richTextPropertyValueEditor = new RichTextPropertyEditor.RichTextPropertyValueEditor(attribute, umbracoContextAccessor, imageSourceParser, localLinkParser, pastedImages);
_mediaPickerPropertyValueEditor = new MediaPickerPropertyEditor.MediaPickerPropertyValueEditor(attribute);
}

/// <summary>
Expand All @@ -84,7 +98,7 @@ public override object FromEditor(ContentPropertyData editorValue, object curren
var mediaParent = config?.MediaParentId;
var mediaParentId = mediaParent == null ? Guid.Empty : mediaParent.Guid;

var grid = DeserializeGridValue(rawJson, out var rtes);
var grid = DeserializeGridValue(rawJson, out var rtes, out _);

var userId = _umbracoContextAccessor.UmbracoContext?.Security.CurrentUser.Id ?? Constants.Security.SuperUserId;

Expand Down Expand Up @@ -117,7 +131,7 @@ public override object ToEditor(Property property, IDataTypeService dataTypeServ
var val = property.GetValue(culture, segment);
if (val == null) return string.Empty;

var grid = DeserializeGridValue(val.ToString(), out var rtes);
var grid = DeserializeGridValue(val.ToString(), out var rtes, out _);

//process the rte values
foreach (var rte in rtes.ToList())
Expand All @@ -131,16 +145,41 @@ public override object ToEditor(Property property, IDataTypeService dataTypeServ
return grid;
}

private GridValue DeserializeGridValue(string rawJson, out IEnumerable<GridValue.GridControl> richTextValues)
private GridValue DeserializeGridValue(string rawJson, out IEnumerable<GridValue.GridControl> richTextValues, out IEnumerable<GridValue.GridControl> mediaValues)
{
var grid = JsonConvert.DeserializeObject<GridValue>(rawJson);

// Find all controls that use the RTE editor
var controls = grid.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls));
var controls = grid.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls)).ToArray();
Comment thread
Shazwazza marked this conversation as resolved.
richTextValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "rte");
mediaValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "media");

return grid;
}

/// <summary>
/// Resolve references from <see cref="IDataValueEditor"/> values
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString();

DeserializeGridValue(rawJson, out var richTextEditorValues, out var mediaValues);

foreach (var umbracoEntityReference in richTextEditorValues.SelectMany(x =>
_richTextPropertyValueEditor.GetReferences(x.Value)))
{
yield return umbracoEntityReference;
}

foreach (var umbracoEntityReference in mediaValues.SelectMany(x =>
_mediaPickerPropertyValueEditor.GetReferences(x.Value["udi"])))
{
yield return umbracoEntityReference;
}
}
}
}
}
29 changes: 27 additions & 2 deletions src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Umbraco.Core;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.PropertyEditors;

namespace Umbraco.Web.PropertyEditors
Expand All @@ -17,14 +19,37 @@ namespace Umbraco.Web.PropertyEditors
Icon = Constants.Icons.MediaImage)]
public class MediaPickerPropertyEditor : DataEditor
{

/// <summary>
/// Initializes a new instance of the <see cref="MediaPickerPropertyEditor"/> class.
/// </summary>
public MediaPickerPropertyEditor(ILogger logger)
: base(logger)
{ }
{
}

/// <inheritdoc />
protected override IConfigurationEditor CreateConfigurationEditor() => new MediaPickerConfigurationEditor();

protected override IDataValueEditor CreateValueEditor() => new MediaPickerPropertyValueEditor(Attribute);

internal class MediaPickerPropertyValueEditor : DataValueEditor, IDataValueReference
{
public MediaPickerPropertyValueEditor(DataEditorAttribute attribute) : base(attribute)
{
}

public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var asString = value is string str ? str : value?.ToString();

if (string.IsNullOrEmpty(asString)) yield break;

if (Udi.TryParse(asString, out var udi))
yield return new UmbracoEntityReference(udi);
}
}
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Umbraco.Core;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.PropertyEditors;

namespace Umbraco.Web.PropertyEditors
Expand All @@ -18,5 +20,30 @@ public MultiNodeTreePickerPropertyEditor(ILogger logger)
{ }

protected override IConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor();

protected override IDataValueEditor CreateValueEditor() => new MultiNodeTreePickerPropertyValueEditor(Attribute);

public class MultiNodeTreePickerPropertyValueEditor : DataValueEditor, IDataValueReference
{
public MultiNodeTreePickerPropertyValueEditor(DataEditorAttribute attribute): base(attribute)
{

}

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 (Udi.TryParse(udiPath, out var udi))
yield return new UmbracoEntityReference(udi);
}

}
}
}


}
22 changes: 21 additions & 1 deletion src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Umbraco.Web.PropertyEditors
{
public class MultiUrlPickerValueEditor : DataValueEditor
public class MultiUrlPickerValueEditor : DataValueEditor, IDataValueReference
{
private readonly IEntityService _entityService;
private readonly ILogger _logger;
Expand Down Expand Up @@ -174,5 +174,25 @@ internal class LinkDto
[DataMember(Name = "queryString")]
public string QueryString { get; set; }
}

public IEnumerable<UmbracoEntityReference> GetReferences(object value)
{
var asString = value == null ? string.Empty : value is string str ? str : value.ToString();

if (string.IsNullOrEmpty(asString)) yield break;

var links = JsonConvert.DeserializeObject<List<LinkDto>>(asString);
foreach (var link in links)
{
if (link.Udi != null) // Links can be absolute links without a Udi
{
yield return new UmbracoEntityReference(link.Udi);
}

}



}
}
}
Loading