Refactors the usage of ICultureDictionary so its injectable, removes more uses of Current, removes unused methods relying on System.Web

This commit is contained in:
Shannon
2019-11-22 13:13:19 +11:00
parent e51a3efe15
commit 3dbebfb153
30 changed files with 140 additions and 155 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
@@ -18,6 +19,7 @@ namespace Umbraco.Web.Models.Mapping
internal class ContentMapDefinition : IMapDefinition
{
private readonly CommonMapper _commonMapper;
private readonly ICultureDictionary _cultureDictionary;
private readonly ILocalizedTextService _localizedTextService;
private readonly IContentService _contentService;
private readonly IContentTypeService _contentTypeService;
@@ -32,11 +34,12 @@ namespace Umbraco.Web.Models.Mapping
private readonly ContentBasicSavedStateMapper<ContentPropertyBasic> _basicStateMapper;
private readonly ContentVariantMapper _contentVariantMapper;
public ContentMapDefinition(CommonMapper commonMapper, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
public ContentMapDefinition(CommonMapper commonMapper, ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, ILocalizationService localizationService, ILogger logger,
IUserService userService)
{
_commonMapper = commonMapper;
_cultureDictionary = cultureDictionary;
_localizedTextService = localizedTextService;
_contentService = contentService;
_contentTypeService = contentTypeService;
@@ -47,7 +50,7 @@ namespace Umbraco.Web.Models.Mapping
_logger = logger;
_userService = userService;
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(localizedTextService);
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(cultureDictionary, localizedTextService);
_stateMapper = new ContentSavedStateMapper<ContentPropertyDisplay>();
_basicStateMapper = new ContentBasicSavedStateMapper<ContentPropertyBasic>();
_contentVariantMapper = new ContentVariantMapper(_localizationService);
@@ -75,7 +78,7 @@ namespace Umbraco.Web.Models.Mapping
target.ContentApps = _commonMapper.GetContentApps(source);
target.ContentTypeId = source.ContentType.Id;
target.ContentTypeAlias = source.ContentType.Alias;
target.ContentTypeName = _localizedTextService.UmbracoDictionaryTranslate(source.ContentType.Name);
target.ContentTypeName = _localizedTextService.UmbracoDictionaryTranslate(_cultureDictionary, source.ContentType.Name);
target.DocumentType = _commonMapper.GetContentType(source, context);
target.Icon = source.ContentType.Icon;
target.Id = source.Id;
@@ -231,7 +234,7 @@ namespace Umbraco.Web.Models.Mapping
return contentType.AllowedTemplates
.Where(t => t.Alias.IsNullOrWhiteSpace() == false && t.Name.IsNullOrWhiteSpace() == false)
.ToDictionary(t => t.Alias, t => _localizedTextService.UmbracoDictionaryTranslate(t.Name));
.ToDictionary(t => t.Alias, t => _localizedTextService.UmbracoDictionaryTranslate(_cultureDictionary, t.Name));
}
private string GetDefaultTemplate(IContent source)

View File

@@ -1,4 +1,5 @@
using Umbraco.Core.Logging;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
@@ -12,11 +13,13 @@ namespace Umbraco.Web.Models.Mapping
/// </summary>
internal class ContentPropertyDisplayMapper : ContentPropertyBasicMapper<ContentPropertyDisplay>
{
private readonly ICultureDictionary _cultureDictionary;
private readonly ILocalizedTextService _textService;
public ContentPropertyDisplayMapper(IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger logger, PropertyEditorCollection propertyEditors)
public ContentPropertyDisplayMapper(ICultureDictionary cultureDictionary, IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger logger, PropertyEditorCollection propertyEditors)
: base(dataTypeService, entityService, logger, propertyEditors)
{
_cultureDictionary = cultureDictionary;
_textService = textService;
}
public override void Map(IProperty originalProp, ContentPropertyDisplay dest, MapperContext context)
@@ -59,8 +62,8 @@ namespace Umbraco.Web.Models.Mapping
}
//Translate
dest.Label = _textService.UmbracoDictionaryTranslate(dest.Label);
dest.Description = _textService.UmbracoDictionaryTranslate(dest.Description);
dest.Label = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Label);
dest.Description = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Description);
}
}
}

View File

@@ -1,4 +1,5 @@
using Umbraco.Core.Logging;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
@@ -17,11 +18,11 @@ namespace Umbraco.Web.Models.Mapping
private readonly ContentPropertyDtoMapper _contentPropertyDtoConverter;
private readonly ContentPropertyDisplayMapper _contentPropertyDisplayMapper;
public ContentPropertyMapDefinition(IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger logger, PropertyEditorCollection propertyEditors)
public ContentPropertyMapDefinition(ICultureDictionary cultureDictionary, IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger logger, PropertyEditorCollection propertyEditors)
{
_contentPropertyBasicConverter = new ContentPropertyBasicMapper<ContentPropertyBasic>(dataTypeService, entityService, logger, propertyEditors);
_contentPropertyDtoConverter = new ContentPropertyDtoMapper(dataTypeService, entityService, logger, propertyEditors);
_contentPropertyDisplayMapper = new ContentPropertyDisplayMapper(dataTypeService, entityService, textService, logger, propertyEditors);
_contentPropertyDisplayMapper = new ContentPropertyDisplayMapper(cultureDictionary, dataTypeService, entityService, textService, logger, propertyEditors);
}
public void DefineMaps(UmbracoMapper mapper)

View File

@@ -1,6 +1,7 @@
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
@@ -21,7 +22,7 @@ namespace Umbraco.Web.Models.Mapping
private readonly IMediaTypeService _mediaTypeService;
private readonly TabsAndPropertiesMapper<IMedia> _tabsAndPropertiesMapper;
public MediaMapDefinition(ILogger logger, CommonMapper commonMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
public MediaMapDefinition(ICultureDictionary cultureDictionary, ILogger logger, CommonMapper commonMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
ILocalizedTextService localizedTextService)
{
_logger = logger;
@@ -29,7 +30,7 @@ namespace Umbraco.Web.Models.Mapping
_mediaService = mediaService;
_mediaTypeService = mediaTypeService;
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IMedia>(localizedTextService);
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IMedia>(cultureDictionary, localizedTextService);
}
public void DefineMaps(UmbracoMapper mapper)

View File

@@ -10,6 +10,7 @@ using Umbraco.Core.Models.Membership;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Core.Dictionary;
namespace Umbraco.Web.Models.Mapping
{
@@ -26,15 +27,13 @@ namespace Umbraco.Web.Models.Mapping
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly ILocalizedTextService _localizedTextService;
private readonly IMemberTypeService _memberTypeService;
private readonly IMemberService _memberService;
private readonly IUserService _userService;
public MemberTabsAndPropertiesMapper(IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberService memberService, IUserService userService, IMemberTypeService memberTypeService)
: base(localizedTextService)
public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IUserService userService, IMemberTypeService memberTypeService)
: base(cultureDictionary, localizedTextService)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
_memberService = memberService ?? throw new ArgumentNullException(nameof(memberService));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_memberTypeService = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService));
}
@@ -123,7 +122,7 @@ namespace Umbraco.Web.Models.Mapping
{
Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}doctype",
Label = _localizedTextService.Localize("content/membertype"),
Value = _localizedTextService.UmbracoDictionaryTranslate(member.ContentType.Name),
Value = _localizedTextService.UmbracoDictionaryTranslate(CultureDictionary, member.ContentType.Name),
View = Current.PropertyEditors[Constants.PropertyEditors.Aliases.Label].GetValueEditor().View
},
GetLoginProperty(_memberTypeService, member, _localizedTextService),

View File

@@ -7,22 +7,25 @@ using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Composing;
using Umbraco.Core.Dictionary;
namespace Umbraco.Web.Models.Mapping
{
internal abstract class TabsAndPropertiesMapper
{
protected ICultureDictionary CultureDictionary { get; }
protected ILocalizedTextService LocalizedTextService { get; }
protected IEnumerable<string> IgnoreProperties { get; set; }
protected TabsAndPropertiesMapper(ILocalizedTextService localizedTextService)
protected TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService)
{
CultureDictionary = cultureDictionary ?? throw new ArgumentNullException(nameof(cultureDictionary));
LocalizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
IgnoreProperties = new List<string>();
}
protected TabsAndPropertiesMapper(ILocalizedTextService localizedTextService, IEnumerable<string> ignoreProperties)
: this(localizedTextService)
protected TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IEnumerable<string> ignoreProperties)
: this(cultureDictionary, localizedTextService)
{
IgnoreProperties = ignoreProperties ?? throw new ArgumentNullException(nameof(ignoreProperties));
}
@@ -115,8 +118,8 @@ namespace Umbraco.Web.Models.Mapping
internal class TabsAndPropertiesMapper<TSource> : TabsAndPropertiesMapper
where TSource : IContentBase
{
public TabsAndPropertiesMapper(ILocalizedTextService localizedTextService)
: base(localizedTextService)
public TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService)
: base(cultureDictionary, localizedTextService)
{ }
public virtual IEnumerable<Tab<ContentPropertyDisplay>> Map(TSource source, MapperContext context)
@@ -159,7 +162,7 @@ namespace Umbraco.Web.Models.Mapping
{
Id = groupId,
Alias = groupName,
Label = LocalizedTextService.UmbracoDictionaryTranslate(groupName),
Label = LocalizedTextService.UmbracoDictionaryTranslate(CultureDictionary, groupName),
Properties = mappedProperties,
IsActive = false
});