Property source level variation should only be applied when configured (#16270)
This commit is contained in:
@@ -25,7 +25,7 @@ internal class Property : PublishedPropertyBase
|
||||
// the invariant-neutral source and inter values
|
||||
private readonly object? _sourceValue;
|
||||
private readonly ContentVariation _variations;
|
||||
private bool _sourceValueIsInvariant;
|
||||
private readonly ContentVariation _sourceVariations;
|
||||
|
||||
// the variant and non-variant object values
|
||||
private CacheValues? _cacheValues;
|
||||
@@ -88,7 +88,7 @@ internal class Property : PublishedPropertyBase
|
||||
// this variable is used for contextualizing the variation level when calculating property values.
|
||||
// it must be set to the union of variance (the combination of content type and property type variance).
|
||||
_variations = propertyType.Variations | content.ContentType.Variations;
|
||||
_sourceValueIsInvariant = propertyType.Variations is ContentVariation.Nothing;
|
||||
_sourceVariations = propertyType.Variations;
|
||||
}
|
||||
|
||||
// clone for previewing as draft a published content that is published and has no draft
|
||||
@@ -104,7 +104,7 @@ internal class Property : PublishedPropertyBase
|
||||
_isMember = origin._isMember;
|
||||
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
|
||||
_variations = origin._variations;
|
||||
_sourceValueIsInvariant = origin._sourceValueIsInvariant;
|
||||
_sourceVariations = origin._sourceVariations;
|
||||
}
|
||||
|
||||
// used to cache the CacheValues of this property
|
||||
@@ -148,9 +148,14 @@ internal class Property : PublishedPropertyBase
|
||||
|
||||
public override object? GetSourceValue(string? culture = null, string? segment = null)
|
||||
{
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
||||
_content.VariationContextAccessor.ContextualizeVariation(_sourceVariations, _content.Id, ref culture, ref segment);
|
||||
|
||||
if (_sourceValueIsInvariant || (culture == string.Empty && segment == string.Empty))
|
||||
// source values are tightly bound to the property/schema culture and segment configurations, so we need to
|
||||
// sanitize the contextualized culture/segment states before using them to access the source values.
|
||||
culture = _sourceVariations.VariesByCulture() ? culture : string.Empty;
|
||||
segment = _sourceVariations.VariesBySegment() ? segment : string.Empty;
|
||||
|
||||
if (culture == string.Empty && segment == string.Empty)
|
||||
{
|
||||
return _sourceValue;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,28 @@ public class PublishedContentVarianceTests
|
||||
Assert.AreEqual(expectedValue, value);
|
||||
}
|
||||
|
||||
[TestCase(DaCulture, Segment1, "DaDk property value")]
|
||||
[TestCase(DaCulture, Segment2, "DaDk property value")]
|
||||
[TestCase(EnCulture, Segment1, "EnUs property value")]
|
||||
[TestCase(EnCulture, Segment2, "EnUs property value")]
|
||||
public void Content_Culture_And_Segment_Variation_Can_Get_Culture_Variant_Property(string culture, string segment, string expectedValue)
|
||||
{
|
||||
var content = CreatePublishedContent(ContentVariation.CultureAndSegment, ContentVariation.Culture, variationContextCulture: culture, variationContextSegment: segment);
|
||||
var value = GetPropertyValue(content);
|
||||
Assert.AreEqual(expectedValue, value);
|
||||
}
|
||||
|
||||
[TestCase(DaCulture, Segment1, "Segment1 property value")]
|
||||
[TestCase(DaCulture, Segment2, "Segment2 property value")]
|
||||
[TestCase(EnCulture, Segment1, "Segment1 property value")]
|
||||
[TestCase(EnCulture, Segment2, "Segment2 property value")]
|
||||
public void Content_Culture_And_Segment_Variation_Can_Get_Segment_Variant_Property(string culture, string segment, string expectedValue)
|
||||
{
|
||||
var content = CreatePublishedContent(ContentVariation.CultureAndSegment, ContentVariation.Segment, variationContextCulture: culture, variationContextSegment: segment);
|
||||
var value = GetPropertyValue(content);
|
||||
Assert.AreEqual(expectedValue, value);
|
||||
}
|
||||
|
||||
private object? GetPropertyValue(IPublishedContent content) => content.GetProperty(PropertyTypeAlias)!.GetValue();
|
||||
|
||||
private IPublishedContent CreatePublishedContent(ContentVariation contentTypeVariation, ContentVariation propertyTypeVariation, string? variationContextCulture = null, string? variationContextSegment = null)
|
||||
|
||||
Reference in New Issue
Block a user