From d99beb0c8b59db9743c3f9ee1bcdcd46161d1e14 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 20 Apr 2018 13:26:45 +1000 Subject: [PATCH] Gets the tree to display the culture specific name --- .../Implement/EntityRepository.cs | 2 +- .../Services/EntityServiceTests.cs | 2 +- .../Trees/ContentTreeControllerBase.cs | 30 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs index 6e34030b29..e1499b8f61 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs @@ -899,7 +899,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { variantInfo[info.LanguageId] = info.Name; } - entity.AdditionalData["VariantInfo"] = variantInfo; + entity.AdditionalData["CultureNames"] = variantInfo; } return entity; } diff --git a/src/Umbraco.Tests/Services/EntityServiceTests.cs b/src/Umbraco.Tests/Services/EntityServiceTests.cs index d7acc6e177..ebf4ea4cb3 100644 --- a/src/Umbraco.Tests/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests/Services/EntityServiceTests.cs @@ -466,7 +466,7 @@ namespace Umbraco.Tests.Services if (i % 2 == 0) { Assert.AreEqual(1, entities[i].AdditionalData.Count); - Assert.AreEqual("VariantInfo", entities[i].AdditionalData.Keys.First()); + Assert.AreEqual("CultureNames", entities[i].AdditionalData.Keys.First()); var variantInfo = entities[i].AdditionalData.First().Value as IDictionary; Assert.IsNotNull(variantInfo); var keys = variantInfo.Keys.ToList(); diff --git a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs index 488b1097c0..abab847151 100644 --- a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs @@ -209,22 +209,24 @@ namespace Umbraco.Web.Trees { result = Services.EntityService.GetChildren(entityId, UmbracoObjectType).ToArray(); } - - if (langId.HasValue) + + //This should really never be null, but we'll error check anyways + int? currLangId = langId.HasValue ? langId.Value : Services.LocalizationService.GetDefaultVariantLanguage()?.Id; + + //Try to see if there is a variant name for the current language for the item and set the name accordingly. + //If any of this fails, the tree node name will remain the default invariant culture name. + //fixme - what if there is no name found at all ? This could occur if the doc type is variant and the user fills in all language values, then creates a new lang, sets it as default and deletes all other pre-existing langs + if (currLangId.HasValue) { - //need to update all node names - //TODO: This is not currently stored, we need to wait until U4-11128 is complete for this to work, in the meantime - // we'll mock using this and it will just be some mock data - foreach(var e in result) + foreach (var e in result) { - if (e.AdditionalData.TryGetValue("VariantInfo", out var variantNames)) - { - var casted = (IDictionary)variantNames; - e.Name = casted[langId.Value]; - } - else - { - e.Name = e.Name + " (lang: " + langId.Value + ")"; + if (e.AdditionalData.TryGetValue("CultureNames", out var cultureNames) + && cultureNames is IDictionary cnd) + { + if (cnd.TryGetValue(currLangId.Value, out var name)) + { + e.Name = name; + } } } }