private Item GetOrAutoCreateItem([NotNull] string relativePath, [CanBeNull] string defaultValue) { relativePath = AssertRelativePath(relativePath); var item = this.Dictionary.Root.Axes.GetItem(relativePath); if (item != null) { return(item); } if (!this.Dictionary.AutoCreate || defaultValue == null) { return(null); } try { return(CreateDictionaryEntryService.CreateDictionaryEntry(this.Dictionary, relativePath, defaultValue)); } catch (Exception ex) { Log.Error($"Failed to get or create {relativePath} from the dictionary in site {this.Dictionary.Site.Name}", ex, this); return(null); } }
public void CreateDictionaryEntry_Call_CreateItems(Db db, [Content] DictionaryEntryTemplate entryTemplate, [Content] DbItem rootItem, IEnumerable <string> pathParts, string defaultValue) { //Arrange var dictionary = new Dictionary() { Root = db.GetItem(rootItem.ID) }; var path = string.Join("/", pathParts.Select(ItemUtil.ProposeValidItemName)); //Act var phraseItem = CreateDictionaryEntryService.CreateDictionaryEntry(dictionary, path, defaultValue); //Assert phraseItem.Should().NotBeNull(); phraseItem.TemplateID.Should().Be(Templates.DictionaryEntry.ID); phraseItem.Paths.FullPath.Should().Be($"{rootItem.FullPath}/{path}"); phraseItem[Templates.DictionaryEntry.Fields.Phrase].Should().Be(defaultValue); }