Changes api to GetData

This commit is contained in:
Shannon
2020-02-06 16:52:34 +11:00
parent 39c0e686ff
commit 45e892f350
4 changed files with 22 additions and 16 deletions

View File

@@ -10,10 +10,9 @@ namespace Umbraco.Core.Models.Blocks
[DataContract(Name = "blockListLayout", Namespace = "")]
public class BlockListLayoutReference : IBlockElement<IPublishedElement>
{
public BlockListLayoutReference(Udi udi, IPublishedElement data, IPublishedElement settings)
public BlockListLayoutReference(Udi udi, IPublishedElement settings)
{
Udi = udi ?? throw new ArgumentNullException(nameof(udi));
Data = data ?? throw new ArgumentNullException(nameof(data));
Settings = settings; // can be null
}
@@ -29,13 +28,5 @@ namespace Umbraco.Core.Models.Blocks
[DataMember(Name = "settings")]
public IPublishedElement Settings { get; }
/// <summary>
/// The data item referenced
/// </summary>
/// <remarks>
/// This is ignored from serialization since it is just a reference to the actual data element
/// </remarks>
[IgnoreDataMember]
public IPublishedElement Data { get; }
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Core.Models.PublishedContent;
@@ -22,6 +23,17 @@ namespace Umbraco.Core.Models.Blocks
[DataMember(Name = "layout")]
public IEnumerable<BlockListLayoutReference> Layout { get; }
/// <summary>
/// Returns the data item associated with the layout udi reference
/// </summary>
/// <param name="udi"></param>
/// <returns></returns>
public IPublishedElement GetData(Udi udi)
{
if (!(udi is GuidUdi guidUdi))
return null;
return Data.FirstOrDefault(x => x.Key == guidUdi.Guid);
}
}
}