* Remove null check from MapperContext.SetCulture and .SetSegment We need to be able to set these to null, since null = invariant / default segment * show segment label on property * Add ContentVariation to ContentPropertyDisplay * Add ContentVariation to DocumentTypeDisplay * Change variations to be on ContentTypeBasic.cs * don't cache value * show correct label and unlock text for culture and segment variations * make lock overlay take up less space Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using Umbraco.Cms.Core.Mapping;
|
|
|
|
namespace Umbraco.Extensions;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for the <see cref="MapperContext" /> class.
|
|
/// </summary>
|
|
public static class MapperContextExtensions
|
|
{
|
|
private const string CultureKey = "Map.Culture";
|
|
private const string SegmentKey = "Map.Segment";
|
|
private const string IncludedPropertiesKey = "Map.IncludedProperties";
|
|
|
|
/// <summary>
|
|
/// Gets the context culture.
|
|
/// </summary>
|
|
public static string? GetCulture(this MapperContext context) =>
|
|
context.HasItems && context.Items.TryGetValue(CultureKey, out var obj) && obj is string s ? s : null;
|
|
|
|
/// <summary>
|
|
/// Gets the context segment.
|
|
/// </summary>
|
|
public static string? GetSegment(this MapperContext context) =>
|
|
context.HasItems && context.Items.TryGetValue(SegmentKey, out var obj) && obj is string s ? s : null;
|
|
|
|
/// <summary>
|
|
/// Sets a context culture.
|
|
/// </summary>
|
|
public static void SetCulture(this MapperContext context, string? culture) => context.Items[CultureKey] = culture;
|
|
|
|
/// <summary>
|
|
/// Sets a context segment.
|
|
/// </summary>
|
|
public static void SetSegment(this MapperContext context, string? segment) => context.Items[SegmentKey] = segment;
|
|
|
|
/// <summary>
|
|
/// Get included properties.
|
|
/// </summary>
|
|
public static string[]? GetIncludedProperties(this MapperContext context) => context.HasItems &&
|
|
context.Items.TryGetValue(IncludedPropertiesKey, out var obj) && obj is string[] s
|
|
? s
|
|
: null;
|
|
|
|
/// <summary>
|
|
/// Sets included properties.
|
|
/// </summary>
|
|
public static void SetIncludedProperties(this MapperContext context, string[] properties) =>
|
|
context.Items[IncludedPropertiesKey] = properties;
|
|
}
|