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

@@ -69,6 +69,9 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "allowCultureVariant")]
public bool AllowCultureVariant { get; set; }
[DataMember(Name = "allowSegmentVariant")]
public bool AllowSegmentVariant { get; set; }
//Tabs
[DataMember(Name = "groups")]
public IEnumerable<PropertyGroupBasic<TPropertyType>> Groups { get; set; }

View File

@@ -24,6 +24,9 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "name", IsRequired = true)]
public string Name { get; set; }
[DataMember(Name = "displayName")]
public string DisplayName { get; set; }
/// <summary>
/// Defines the tabs containing display properties
/// </summary>

View File

@@ -20,9 +20,12 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "defaultTemplate")]
public EntityBasic DefaultTemplate { get; set; }
[DataMember(Name = "allowCultureVariant")]
public bool AllowCultureVariant { get; set; }
[DataMember(Name = "allowSegmentVariant")]
public bool AllowSegmentVariant { get; set; }
}
}

View File

@@ -132,6 +132,7 @@ namespace Umbraco.Web.Models.Mapping
MapTypeToDisplayBase<DocumentTypeDisplay, PropertyTypeDisplay>(source, target);
target.AllowCultureVariant = source.VariesByCulture();
target.AllowSegmentVariant = source.VariesBySegment();
//sync templates
target.AllowedTemplates = context.MapEnumerable<ITemplate, EntityBasic>(source.AllowedTemplates);
@@ -245,6 +246,7 @@ namespace Umbraco.Web.Models.Mapping
target.ValidationRegExp = source.Validation.Pattern;
target.ValidationRegExpMessage = source.Validation.PatternMessage;
target.SetVariesBy(ContentVariation.Culture, source.AllowCultureVariant);
target.SetVariesBy(ContentVariation.Segment, source.AllowSegmentVariant);
if (source.Id > 0)
target.Id = source.Id;
@@ -356,6 +358,7 @@ namespace Umbraco.Web.Models.Mapping
{
target.Alias = source.Alias;
target.AllowCultureVariant = source.AllowCultureVariant;
target.AllowSegmentVariant = source.AllowSegmentVariant;
target.DataTypeId = source.DataTypeId;
target.DataTypeKey = source.DataTypeKey;
target.Description = source.Description;
@@ -372,6 +375,7 @@ namespace Umbraco.Web.Models.Mapping
{
target.Alias = source.Alias;
target.AllowCultureVariant = source.AllowCultureVariant;
target.AllowSegmentVariant = source.AllowSegmentVariant;
target.DataTypeId = source.DataTypeId;
target.DataTypeKey = source.DataTypeKey;
target.Description = source.Description;
@@ -417,6 +421,7 @@ namespace Umbraco.Web.Models.Mapping
if (!(target is IMemberType))
{
target.SetVariesBy(ContentVariation.Culture, source.AllowCultureVariant);
target.SetVariesBy(ContentVariation.Segment, source.AllowSegmentVariant);
}
// handle property groups and property types

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);
}
}
}

View File

@@ -244,7 +244,8 @@ namespace Umbraco.Web.Models.Mapping
SortOrder = p.SortOrder,
ContentTypeId = contentType.Id,
ContentTypeName = contentType.Name,
AllowCultureVariant = p.VariesByCulture()
AllowCultureVariant = p.VariesByCulture(),
AllowSegmentVariant = p.VariesBySegment()
});
}