diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedValueFallback.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedValueFallback.cs
index 0524ee98a91f..c1601e8a5289 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedValueFallback.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedValueFallback.cs
@@ -30,7 +30,7 @@ public bool TryGetValue(IPublishedProperty property, string? culture, string? se
///
public bool TryGetValue(IPublishedProperty property, string? culture, string? segment, Fallback fallback, T? defaultValue, out T? value)
{
- _variationContextAccessor.ContextualizeVariation(property.PropertyType.Variations, ref culture, ref segment);
+ _variationContextAccessor.ContextualizeVariation(property.PropertyType.Variations, property.Alias, ref culture, ref segment);
foreach (var f in fallback)
{
@@ -78,7 +78,7 @@ public bool TryGetValue(IPublishedElement content, string alias, string? cult
return false;
}
- _variationContextAccessor.ContextualizeVariation(propertyType.Variations, ref culture, ref segment);
+ _variationContextAccessor.ContextualizeVariation(propertyType.Variations, alias, ref culture, ref segment);
foreach (var f in fallback)
{
@@ -124,7 +124,7 @@ public virtual bool TryGetValue(IPublishedContent content, string alias, stri
IPublishedPropertyType? propertyType = content.ContentType.GetPropertyType(alias);
if (propertyType != null)
{
- _variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, ref culture, ref segment);
+ _variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, alias, ref culture, ref segment);
noValueProperty = content.GetProperty(alias);
}
@@ -195,7 +195,7 @@ private bool TryGetValueWithAncestorsFallback(IPublishedContent? content, str
{
culture = null;
segment = null;
- _variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, ref culture, ref segment);
+ _variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, alias, ref culture, ref segment);
}
property = content?.GetProperty(alias);
diff --git a/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs b/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs
index 92326ae35955..395e0f9c203e 100644
--- a/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs
@@ -25,9 +25,15 @@ public VariationContext(string? culture = null, string? segment = null)
public string Segment { get; }
///
- /// Gets the segment for the content item
+ /// Gets the segment for the content item.
///
- ///
- ///
+ /// The content Id.
public virtual string GetSegment(int contentId) => Segment;
+
+ ///
+ /// Gets the segment for the content item and property alias.
+ ///
+ /// The content Id.
+ /// The property alias.
+ public virtual string GetSegment(int contentId, string propertyAlias) => Segment;
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/VariationContextAccessorExtensions.cs b/src/Umbraco.Core/Models/PublishedContent/VariationContextAccessorExtensions.cs
index e8f6e3bdc1a7..566d5e45af08 100644
--- a/src/Umbraco.Core/Models/PublishedContent/VariationContextAccessorExtensions.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/VariationContextAccessorExtensions.cs
@@ -8,25 +8,45 @@ namespace Umbraco.Extensions;
public static class VariationContextAccessorExtensions
{
+ [Obsolete("Please use the method overload that accepts all parameters. Scheduled for removal in Umbraco 18.")]
public static void ContextualizeVariation(
this IVariationContextAccessor variationContextAccessor,
ContentVariation variations,
ref string? culture,
ref string? segment)
- => variationContextAccessor.ContextualizeVariation(variations, null, ref culture, ref segment);
+ => variationContextAccessor.ContextualizeVariation(variations, null, null, ref culture, ref segment);
+ public static void ContextualizeVariation(
+ this IVariationContextAccessor variationContextAccessor,
+ ContentVariation variations,
+ string? propertyAlias,
+ ref string? culture,
+ ref string? segment)
+ => variationContextAccessor.ContextualizeVariation(variations, null, propertyAlias, ref culture, ref segment);
+
+ [Obsolete("Please use the method overload that accepts all parameters. Scheduled for removal in Umbraco 18.")]
public static void ContextualizeVariation(
this IVariationContextAccessor variationContextAccessor,
ContentVariation variations,
int contentId,
ref string? culture,
ref string? segment)
- => variationContextAccessor.ContextualizeVariation(variations, (int?)contentId, ref culture, ref segment);
+ => variationContextAccessor.ContextualizeVariation(variations, (int?)contentId, null, ref culture, ref segment);
+
+ public static void ContextualizeVariation(
+ this IVariationContextAccessor variationContextAccessor,
+ ContentVariation variations,
+ int contentId,
+ string? propertyAlias,
+ ref string? culture,
+ ref string? segment)
+ => variationContextAccessor.ContextualizeVariation(variations, (int?)contentId, propertyAlias, ref culture, ref segment);
private static void ContextualizeVariation(
this IVariationContextAccessor variationContextAccessor,
ContentVariation variations,
int? contentId,
+ string? propertyAlias,
ref string? culture,
ref string? segment)
{
@@ -37,18 +57,22 @@ private static void ContextualizeVariation(
// use context values
VariationContext? publishedVariationContext = variationContextAccessor?.VariationContext;
- if (culture == null)
- {
- culture = variations.VariesByCulture() ? publishedVariationContext?.Culture : string.Empty;
- }
+ culture ??= variations.VariesByCulture() ? publishedVariationContext?.Culture : string.Empty;
if (segment == null)
{
if (variations.VariesBySegment())
{
- segment = contentId == null
- ? publishedVariationContext?.Segment
- : publishedVariationContext?.GetSegment(contentId.Value);
+ if (contentId == null)
+ {
+ segment = publishedVariationContext?.Segment;
+ }
+ else
+ {
+ segment = propertyAlias == null ?
+ publishedVariationContext?.GetSegment(contentId.Value) :
+ publishedVariationContext?.GetSegment(contentId.Value, propertyAlias);
+ }
}
else
{
diff --git a/src/Umbraco.PublishedCache.NuCache/Property.cs b/src/Umbraco.PublishedCache.NuCache/Property.cs
index 41532d4944c1..2d5635a12818 100644
--- a/src/Umbraco.PublishedCache.NuCache/Property.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Property.cs
@@ -114,7 +114,7 @@ public Property(Property origin, PublishedContent content)
// determines whether a property has value
public override bool HasValue(string? culture = null, string? segment = null)
{
- _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
+ _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, PropertyType.Alias, ref culture, ref segment);
var value = GetSourceValue(culture, segment);
var hasValue = PropertyType.IsValue(value, PropertyValueLevel.Source);
@@ -148,7 +148,7 @@ public override bool HasValue(string? culture = null, string? segment = null)
public override object? GetSourceValue(string? culture = null, string? segment = null)
{
- _content.VariationContextAccessor.ContextualizeVariation(_sourceVariations, _content.Id, ref culture, ref segment);
+ _content.VariationContextAccessor.ContextualizeVariation(_sourceVariations, _content.Id, PropertyType.Alias, ref culture, ref segment);
// 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.
@@ -262,7 +262,7 @@ private CacheValues GetCacheValues(IAppCache? cache)
public override object? GetValue(string? culture = null, string? segment = null)
{
- _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
+ _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, PropertyType.Alias, ref culture, ref segment);
object? value;
CacheValue cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
@@ -285,7 +285,7 @@ private CacheValues GetCacheValues(IAppCache? cache)
[Obsolete("The current implementation of XPath is suboptimal and will be removed entirely in a future version. Scheduled for removal in v14")]
public override object? GetXPathValue(string? culture = null, string? segment = null)
{
- _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
+ _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, PropertyType.Alias, ref culture, ref segment);
CacheValue cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
@@ -304,7 +304,7 @@ private CacheValues GetCacheValues(IAppCache? cache)
public override object? GetDeliveryApiValue(bool expanding, string? culture = null, string? segment = null)
{
- _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
+ _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, PropertyType.Alias, ref culture, ref segment);
object? value;
CacheValue cacheValues = GetCacheValues(expanding ? PropertyType.DeliveryApiCacheLevelForExpansion : PropertyType.DeliveryApiCacheLevel).For(culture, segment);