Expose "expanding" state in API value conversion (#14312)

* Expose "expanding" state in API value conversion

* Add unit test

* Add non-breaking and obsoletion

* Add compat suppressions
This commit is contained in:
Kenn Jacobsen
2023-05-31 08:46:30 +02:00
committed by GitHub
parent 84a0cd8c09
commit 3b433e6658
36 changed files with 121 additions and 63 deletions

View File

@@ -122,6 +122,11 @@ public interface IPublishedPropertyType
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="inter">The intermediate value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <param name="expanding">A value indicating whether the property value should be expanded.</param>
/// <returns>The object value.</returns>
object? ConvertInterToDeliveryApiObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview);
object? ConvertInterToDeliveryApiObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding);
[Obsolete($"Use the {nameof(ConvertInterToDeliveryApiObject)} that supports property expansion. Will be removed in V14.")]
object? ConvertInterToDeliveryApiObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview)
=> ConvertInterToDeliveryApiObject(owner, referenceCacheLevel, inter, preview, false);
}

View File

@@ -301,7 +301,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
}
/// <inheritdoc />
public object? ConvertInterToDeliveryApiObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview)
public object? ConvertInterToDeliveryApiObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding)
{
if (!_initialized)
{
@@ -311,7 +311,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
// use the converter if any, else just return the inter value
return _converter != null
? _converter is IDeliveryApiPropertyValueConverter deliveryApiPropertyValueConverter
? deliveryApiPropertyValueConverter.ConvertIntermediateToDeliveryApiObject(owner, this, referenceCacheLevel, inter, preview)
? deliveryApiPropertyValueConverter.ConvertIntermediateToDeliveryApiObject(owner, this, referenceCacheLevel, inter, preview, expanding)
: _converter.ConvertIntermediateToObject(owner, this, referenceCacheLevel, inter, preview)
: inter;
}

View File

@@ -41,7 +41,7 @@ public class RawValueProperty : PublishedPropertyBase
_xpathValue = new Lazy<object?>(() =>
PropertyType.ConvertInterToXPath(content, PropertyCacheLevel.Unknown, interValue?.Value, isPreviewing));
_deliveryApiValue = new Lazy<object?>(() =>
PropertyType.ConvertInterToDeliveryApiObject(content, PropertyCacheLevel.Unknown, interValue?.Value, isPreviewing));
PropertyType.ConvertInterToDeliveryApiObject(content, PropertyCacheLevel.Unknown, interValue?.Value, isPreviewing, false));
}
// RawValueProperty does not (yet?) support variants,