Files
Umbraco-CMS/src/Umbraco.Core/DeliveryApi/PropertyRenderer.cs
Kenn Jacobsen 0cdea6120b Add support for property value fallbacks in the delivery API (#14421)
* 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
2023-06-21 08:32:57 +02:00

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;
}
}