Merge remote-tracking branch 'origin/v8/dev' into netcore/dev

# Conflicts:
#	src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs
#	src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
This commit is contained in:
Bjarke Berg
2020-05-11 08:23:59 +02:00
100 changed files with 2622 additions and 1652 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Mapping;
@@ -13,10 +14,12 @@ namespace Umbraco.Web.Models.Mapping
public class ContentVariantMapper
{
private readonly ILocalizationService _localizationService;
private readonly ILocalizedTextService _localizedTextService;
public ContentVariantMapper(ILocalizationService localizationService)
public ContentVariantMapper(ILocalizationService localizationService, ILocalizedTextService localizedTextService)
{
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
_localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
}
public IEnumerable<ContentVariantDisplay> Map(IContent source, MapperContext context)
@@ -113,11 +116,19 @@ namespace Umbraco.Web.Models.Mapping
/// </summary>
/// <param name="content"></param>
/// <returns>
/// Returns all segments assigned to the content including 'null' values
/// Returns all segments assigned to the content including the default `null` segment.
/// </returns>
private IEnumerable<string> GetSegments(IContent content)
{
return content.Properties.SelectMany(p => p.Values.Select(v => v.Segment)).Distinct();
// The default segment (null) is always there,
// even when there is no property data at all yet
var segments = new List<string> { null };
// Add actual segments based on the property values
segments.AddRange(content.Properties.SelectMany(p => p.Values.Select(v => v.Segment)));
// Do not return a segment more than once
return segments.Distinct();
}
private ContentVariantDisplay CreateVariantDisplay(MapperContext context, IContent content, Language language, string segment)
@@ -130,8 +141,31 @@ namespace Umbraco.Web.Models.Mapping
variantDisplay.Segment = segment;
variantDisplay.Language = language;
variantDisplay.Name = content.GetCultureName(language?.IsoCode);
variantDisplay.DisplayName = GetDisplayName(language, segment);
return variantDisplay;
}
private string GetDisplayName(Language language, string segment)
{
var isCultureVariant = language != null;
var isSegmentVariant = !segment.IsNullOrWhiteSpace();
if(!isCultureVariant && !isSegmentVariant)
{
return _localizedTextService.Localize("general/default");
}
var parts = new List<string>();
if (isSegmentVariant)
parts.Add(segment);
if (isCultureVariant)
parts.Add(language.Name);
return string.Join(" — ", parts);
}
}
}