ContentVariantDisplay: add DisplayName property and use in Umbr… (#7677)

This commit is contained in:
Daniël Knippers
2020-02-18 11:47:58 +01:00
committed by GitHub
parent 5a5291d149
commit 12bb2a42d6
8 changed files with 39 additions and 53 deletions

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

@@ -50,7 +50,7 @@ namespace Umbraco.Web.Models.Mapping
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(localizedTextService);
_stateMapper = new ContentSavedStateMapper<ContentPropertyDisplay>();
_basicStateMapper = new ContentBasicSavedStateMapper<ContentPropertyBasic>();
_contentVariantMapper = new ContentVariantMapper(_localizationService);
_contentVariantMapper = new ContentVariantMapper(_localizationService, localizedTextService);
}
public void DefineMaps(UmbracoMapper mapper)
@@ -102,7 +102,7 @@ namespace Umbraco.Web.Models.Mapping
target.ContentDto.Properties = context.MapEnumerable<Property, ContentPropertyDto>(source.Properties);
}
// Umbraco.Code.MapAll -Segment -Language
// Umbraco.Code.MapAll -Segment -Language -DisplayName
private void Map(IContent source, ContentVariantDisplay target, MapperContext context)
{
target.CreateDate = source.CreateDate;

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
internal 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)
@@ -138,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 (isCultureVariant)
parts.Add(new CultureInfo(language.IsoCode).NativeName);
if (isSegmentVariant)
parts.Add(segment);
return string.Join(" - ", parts);
}
}
}