From int languageId to string culture

This commit is contained in:
Stephan
2018-04-21 09:57:28 +02:00
parent 5d1abaa713
commit a69019aea0
64 changed files with 708 additions and 626 deletions

View File

@@ -46,9 +46,9 @@ namespace Umbraco.Web.Models.Mapping
editor = _propertyEditors[Constants.PropertyEditors.Aliases.NoEdit];
}
var languageId = context.GetLanguageId();
var culture = context.GetCulture();
if (!languageId.HasValue && property.PropertyType.Variations == ContentVariation.CultureNeutral)
if (culture == null && property.PropertyType.Variations == ContentVariation.CultureNeutral)
{
//a language Id needs to be set for a property type that can be varried by language
throw new InvalidOperationException($"No languageId found in mapping operation when one is required for the culture neutral property type {property.PropertyType.Alias}");
@@ -74,7 +74,7 @@ namespace Umbraco.Web.Models.Mapping
}
// if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return.
result.Value = editor.GetValueEditor().ToEditor(property, DataTypeService, languageId);
result.Value = editor.GetValueEditor().ToEditor(property, DataTypeService, culture);
return result;
}
}

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Web.Models.Mapping
internal static class ContextMapper
{
public const string UmbracoContextKey = "ContextMapper.UmbracoContext";
public const string LanguageKey = "ContextMapper.LanguageId";
public const string CultureKey = "ContextMapper.Culture";
public static TDestination Map<TSource, TDestination>(TSource obj, UmbracoContext umbracoContext)
=> Mapper.Map<TSource, TDestination>(obj, opt => opt.Items[UmbracoContextKey] = umbracoContext);
@@ -77,12 +77,12 @@ namespace Umbraco.Web.Models.Mapping
/// </summary>
/// <param name="resolutionContext"></param>
/// <returns></returns>
public static int? GetLanguageId(this ResolutionContext resolutionContext)
public static string GetCulture(this ResolutionContext resolutionContext)
{
if (!resolutionContext.Options.Items.TryGetValue(LanguageKey, out var obj)) return null;
if (!resolutionContext.Options.Items.TryGetValue(CultureKey, out var obj)) return null;
if (obj is int i)
return i;
if (obj is string s)
return s;
return null;
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
@@ -29,19 +30,19 @@ namespace Umbraco.Web.Models.Mapping
{
Language = x,
Mandatory = x.Mandatory,
Name = source.GetName(x.Id),
Exists = source.IsCultureAvailable(x.Id), // segments ??
Name = source.GetName(x.IsoCode),
Exists = source.IsCultureAvailable(x.IsoCode), // segments ??
PublishedState = source.PublishedState.ToString(),
//Segment = ?? We'll need to populate this one day when we support segments
}).ToList();
var langId = context.GetLanguageId();
var culture = context.GetCulture();
//set the current variant being edited to the one found in the context or the default if nothing matches
var foundCurrent = false;
foreach (var variant in variants)
{
if (langId.HasValue && langId.Value == variant.Language.Id)
if (culture.InvariantEquals(variant.Language.IsoCode))
{
variant.IsCurrent = true;
foundCurrent = true;