ContentVariantDisplay: add DisplayName property and use in Umbr… (#7677)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user