* Add support for property value fallbacks in the delivery API * Add dedicated tests for the IDeliveryApiPropertyValueConverter interface * Rewrite for less impact and more streamlined with Razor output
24 lines
750 B
C#
24 lines
750 B
C#
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
namespace Umbraco.Cms.Core.DeliveryApi;
|
|
|
|
public class ApiPropertyRenderer : IApiPropertyRenderer
|
|
{
|
|
private readonly IPublishedValueFallback _publishedValueFallback;
|
|
|
|
public ApiPropertyRenderer(IPublishedValueFallback publishedValueFallback)
|
|
=> _publishedValueFallback = publishedValueFallback;
|
|
|
|
public object? GetPropertyValue(IPublishedProperty property, bool expanding)
|
|
{
|
|
if (property.HasValue())
|
|
{
|
|
return property.GetDeliveryApiValue(expanding);
|
|
}
|
|
|
|
return _publishedValueFallback.TryGetValue(property, null, null, Fallback.To(Fallback.None), null, out var fallbackValue)
|
|
? fallbackValue
|
|
: null;
|
|
}
|
|
}
|