Files
Umbraco-CMS/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs

292 lines
13 KiB
C#
Raw Normal View History

2017-07-19 13:42:47 +02:00
using System;
using System.Collections.Generic;
2021-09-15 13:40:08 +02:00
using System.Globalization;
2017-07-19 13:42:47 +02:00
using Examine;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Models.Membership;
2021-02-12 10:57:50 +01:00
using Umbraco.Cms.Infrastructure.Examine;
using Umbraco.Extensions;
2017-07-19 13:42:47 +02:00
namespace Umbraco.Cms.Core.Models.Mapping
2017-07-19 13:42:47 +02:00
{
public class EntityMapDefinition : IMapDefinition
2017-07-19 13:42:47 +02:00
{
Merge remote-tracking branch 'origin/v8/dev' into netcore/dev # Conflicts: # build/NuSpecs/UmbracoCms.Web.nuspec # src/SolutionInfo.cs # src/Umbraco.Core/Cache/MediaCacheRefresher.cs # src/Umbraco.Core/Composing/ComponentCollection.cs # src/Umbraco.Core/Composing/Composers.cs # src/Umbraco.Core/Composing/TypeFinder.cs # src/Umbraco.Core/Composing/TypeLoader.cs # src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs # src/Umbraco.Core/Constants-SvgSanitizer.cs # src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs # src/Umbraco.Core/Extensions/PublishedContentExtensions.cs # src/Umbraco.Core/Extensions/PublishedPropertyExtension.cs # src/Umbraco.Core/Extensions/StringExtensions.cs # src/Umbraco.Core/HealthChecks/Checks/Security/ExcessiveHeadersCheck.cs # src/Umbraco.Core/HealthChecks/HealthCheckResults.cs # src/Umbraco.Core/IO/FileSystems.cs # src/Umbraco.Core/IO/IOHelper.cs # src/Umbraco.Core/IO/MediaFileSystem.cs # src/Umbraco.Core/IO/PhysicalFileSystem.cs # src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs # src/Umbraco.Core/Logging/DisposableTimer.cs # src/Umbraco.Core/Logging/ILogger.cs # src/Umbraco.Core/Logging/LogProfiler.cs # src/Umbraco.Core/Logging/OwinLogger.cs # src/Umbraco.Core/Manifest/ManifestWatcher.cs # src/Umbraco.Core/Mapping/UmbracoMapper.cs # src/Umbraco.Core/Media/UploadAutoFillProperties.cs # src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs # src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs # src/Umbraco.Core/Models/Mapping/ContentPropertyBasicMapper.cs # src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs # src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs # src/Umbraco.Core/Models/Member.cs # src/Umbraco.Core/Packaging/PackageActionRunner.cs # src/Umbraco.Core/PropertyEditors/DataValueEditor.cs # src/Umbraco.Core/PropertyEditors/Validators/EyeDropperColorPickerConfigurationEditor.cs # src/Umbraco.Core/PropertyEditors/Validators/EyeDropperColorPickerPropertyEditor.cs # src/Umbraco.Core/Routing/DefaultUrlProvider.cs # src/Umbraco.Core/Runtime/CoreRuntime.cs # src/Umbraco.Core/Runtime/MainDom.cs # src/Umbraco.Core/RuntimeState.cs # src/Umbraco.Core/Scoping/ScopeProvider.cs # src/Umbraco.Core/Sync/DatabaseServerMessenger.cs # src/Umbraco.Core/Templates/HtmlUrlParser.cs # src/Umbraco.Core/UriExtensions.cs # src/Umbraco.Examine.Lucene/UmbracoContentIndex.cs # src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs # src/Umbraco.Infrastructure/Examine/IndexRebuilder.cs # src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs # src/Umbraco.Infrastructure/Manifest/ManifestParser.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs # src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypeMigration.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs # src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs # src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs # src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs # src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs # src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs # src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs # src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs # src/Umbraco.Infrastructure/PropertyEditors/RichTextEditorPastedImages.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/JsonValueConverter.cs # src/Umbraco.Infrastructure/PublishedCache/PublishedContentTypeCache.cs # src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs # src/Umbraco.Infrastructure/Scoping/Scope.cs # src/Umbraco.Infrastructure/Search/ExamineNotificationHandler.cs # src/Umbraco.Infrastructure/Services/Implement/ContentService.cs # src/Umbraco.Infrastructure/Services/Implement/LocalizedTextService.cs # src/Umbraco.Infrastructure/Services/Implement/LocalizedTextServiceFileSources.cs # src/Umbraco.Infrastructure/Services/Implement/MediaService.cs # src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs # src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs # src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs # src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs # src/Umbraco.PublishedCache.NuCache/ContentStore.cs # src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs # src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs # src/Umbraco.Tests.UnitTests/Umbraco.ModelsBuilder.Embedded/BuilderTests.cs # src/Umbraco.Tests/Composing/TypeLoaderTests.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/BackgroundTaskRunner.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs # src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStoreFilePersister.cs # src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs # src/Umbraco.Tests/Services/PerformanceTests.cs # src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs # src/Umbraco.Tests/Testing/TestingTests/MockTests.cs # src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs # src/Umbraco.Web.BackOffice/Controllers/ContentController.cs # src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs # src/Umbraco.Web.BackOffice/Controllers/ExamineManagementController.cs # src/Umbraco.Web.BackOffice/HealthChecks/HealthCheckController.cs # src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs # src/Umbraco.Web.BackOffice/Services/IconService.cs # src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs # src/Umbraco.Web.Common/Extensions/FormCollectionExtensions.cs # src/Umbraco.Web.Common/Install/InstallApiController.cs # src/Umbraco.Web.Common/Macros/MacroRenderer.cs # src/Umbraco.Web.Common/ModelsBuilder/PureLiveModelFactory.cs # src/Umbraco.Web.UI.Client/package-lock.json # src/Umbraco.Web.UI.Client/src/views/memberTypes/copy.controller.js # src/Umbraco.Web.UI.Client/src/views/memberTypes/copy.html # src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/config/splashes/noNodes.aspx # src/Umbraco.Web/AspNet/AspNetHttpContextAccessor.cs # src/Umbraco.Web/Cache/DistributedCacheBinder.cs # src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs # src/Umbraco.Web/Editors/AuthenticationController.cs # src/Umbraco.Web/Editors/BackOfficeController.cs # src/Umbraco.Web/Editors/Binders/ContentModelBinderHelper.cs # src/Umbraco.Web/Editors/ContentControllerBase.cs # src/Umbraco.Web/Editors/ContentTypeController.cs # src/Umbraco.Web/Editors/DictionaryController.cs # src/Umbraco.Web/Editors/MemberTypeController.cs # src/Umbraco.Web/Editors/PasswordChanger.cs # src/Umbraco.Web/Editors/RelationTypeController.cs # src/Umbraco.Web/Editors/TinyMceController.cs # src/Umbraco.Web/HealthCheck/Checks/Security/HttpsCheck.cs # src/Umbraco.Web/HtmlHelperRenderExtensions.cs # src/Umbraco.Web/HttpUrlHelperExtensions.cs # src/Umbraco.Web/HybridEventMessagesAccessor.cs # src/Umbraco.Web/ImageCropperTemplateExtensions.cs # src/Umbraco.Web/JavaScript/ClientDependencyConfiguration.cs # src/Umbraco.Web/Mvc/RenderMvcController.cs # src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs # src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs # src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs # src/Umbraco.Web/Routing/ContentFinderByIdPath.cs # src/Umbraco.Web/Routing/ContentFinderByRedirectUrl.cs # src/Umbraco.Web/Routing/ContentFinderByUrl.cs # src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs # src/Umbraco.Web/Routing/ContentFinderByUrlAndTemplate.cs # src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs # src/Umbraco.Web/Routing/PublishedRouter.cs # src/Umbraco.Web/Runtime/WebInitialComposer.cs # src/Umbraco.Web/Scheduling/KeepAlive.cs # src/Umbraco.Web/Scheduling/ScheduledPublishing.cs # src/Umbraco.Web/Scheduling/TempFileCleanup.cs # src/Umbraco.Web/Security/MembershipHelper.cs # src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs # src/Umbraco.Web/Trees/MemberTreeController.cs # src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs # src/Umbraco.Web/Trees/MemberTypeTreeController.cs # src/Umbraco.Web/UmbracoApplicationBase.cs # src/Umbraco.Web/UmbracoInjectedModule.cs # src/Umbraco.Web/UmbracoModule.cs # src/Umbraco.Web/WebApi/AngularJsonMediaTypeFormatter.cs # src/Umbraco.Web/WebApi/Filters/FileUploadCleanupFilterAttribute.cs # src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs
2021-04-20 19:34:18 +02:00
public void DefineMaps(IUmbracoMapper mapper)
2019-03-26 10:39:50 +01:00
{
mapper.Define<IEntitySlim, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<PropertyType, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<PropertyGroup, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<IUser, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<ITemplate, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<EntityBasic, ContentTypeSort>((source, context) => new ContentTypeSort(), Map);
mapper.Define<IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
2019-04-21 21:00:34 +02:00
mapper.Define<IEntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
2019-03-26 10:39:50 +01:00
mapper.Define<ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
2019-04-08 10:05:21 +02:00
mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
2019-03-26 10:39:50 +01:00
}
2019-03-26 10:39:50 +01:00
// Umbraco.Code.MapAll -Alias
private static void Map(IEntitySlim source, EntityBasic target, MapperContext context)
2017-07-19 13:42:47 +02:00
{
2019-03-26 10:39:50 +01:00
target.Icon = MapContentTypeIcon(source);
target.Id = source.Id;
target.Key = source.Key;
target.Name = MapName(source, context);
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Trashed = source.Trashed;
target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);
if (source is IContentEntitySlim contentSlim)
{
source.AdditionalData!["ContentTypeAlias"] = contentSlim.ContentTypeAlias;
}
if (source is IDocumentEntitySlim documentSlim)
{
source.AdditionalData!["IsPublished"] = documentSlim.Published;
}
if (source is IMediaEntitySlim mediaSlim)
{
2022-02-24 14:39:29 +01:00
if (source.AdditionalData is not null)
{
//pass UpdateDate for MediaPicker ListView ordering
source.AdditionalData["UpdateDate"] = mediaSlim.UpdateDate;
source.AdditionalData["MediaPath"] = mediaSlim.MediaPath;
}
}
2022-02-24 14:39:29 +01:00
if (source.AdditionalData is not null)
{
2022-02-24 14:39:29 +01:00
// NOTE: we're mapping the objects in AdditionalData by object reference here.
// it works fine for now, but it's something to keep in mind in the future
foreach(var kvp in source.AdditionalData)
{
2022-02-24 14:39:29 +01:00
if (kvp.Value is not null)
{
target.AdditionalData[kvp.Key] = kvp.Value;
}
}
}
2019-03-26 10:39:50 +01:00
target.AdditionalData.Add("IsContainer", source.IsContainer);
}
// Umbraco.Code.MapAll -Udi -Trashed
private static void Map(PropertyType source, EntityBasic target, MapperContext context)
{
target.Alias = source.Alias;
target.Icon = "icon-box";
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = -1;
target.Path = "";
}
// Umbraco.Code.MapAll -Udi -Trashed
private static void Map(PropertyGroup source, EntityBasic target, MapperContext context)
{
target.Alias = source.Alias;
2019-03-26 10:39:50 +01:00
target.Icon = "icon-tab";
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = -1;
target.Path = "";
}
// Umbraco.Code.MapAll -Udi -Trashed
private static void Map(IUser source, EntityBasic target, MapperContext context)
{
target.Alias = source.Username;
target.Icon = Constants.Icons.User;
2019-03-26 10:39:50 +01:00
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = -1;
target.Path = "";
}
// Umbraco.Code.MapAll -Trashed
private static void Map(ITemplate source, EntityBasic target, MapperContext context)
{
target.Alias = source.Alias;
target.Icon = Constants.Icons.Template;
2019-03-26 10:39:50 +01:00
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = -1;
target.Path = source.Path;
target.Udi = Udi.Create(Constants.UdiEntityType.Template, source.Key);
}
// Umbraco.Code.MapAll -SortOrder
private static void Map(EntityBasic source, ContentTypeSort target, MapperContext context)
{
target.Alias = source.Alias;
target.Id = new Lazy<int>(() => Convert.ToInt32(source.Id));
}
// Umbraco.Code.MapAll -Trashed
private static void Map(IContentTypeComposition source, EntityBasic target, MapperContext context)
{
target.Alias = source.Alias;
target.Icon = source.Icon;
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = source.ParentId;
target.Path = source.Path;
2019-04-03 10:39:49 +02:00
target.Udi = ContentTypeMapDefinition.MapContentTypeUdi(source);
2019-03-26 10:39:50 +01:00
}
// Umbraco.Code.MapAll -Trashed -Alias -Score
private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context)
{
target.Icon = MapContentTypeIcon(source);
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.Name;
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);
if (target.Icon.IsNullOrWhiteSpace())
{
if (source.NodeObjectType == Constants.ObjectTypes.Document)
target.Icon = Constants.Icons.Content;
if (source.NodeObjectType == Constants.ObjectTypes.Media)
target.Icon = Constants.Icons.Content;
2019-03-26 10:39:50 +01:00
if (source.NodeObjectType == Constants.ObjectTypes.Member)
target.Icon = Constants.Icons.Member;
2019-03-26 10:39:50 +01:00
else if (source.NodeObjectType == Constants.ObjectTypes.DataType)
target.Icon = Constants.Icons.DataType;
2019-03-26 10:39:50 +01:00
else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType)
target.Icon = Constants.Icons.ContentType;
2019-03-26 10:39:50 +01:00
else if (source.NodeObjectType == Constants.ObjectTypes.MediaType)
target.Icon = Constants.Icons.MediaType;
else if (source.NodeObjectType == Constants.ObjectTypes.MemberType)
target.Icon = Constants.Icons.MemberType;
2019-03-26 10:39:50 +01:00
else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType)
target.Icon = Constants.Icons.Template;
2019-03-26 10:39:50 +01:00
}
}
// Umbraco.Code.MapAll -Alias -Trashed
private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context)
{
target.Id = source.Id;
target.Score = source.Score;
// TODO: Properly map this (not aftermap)
//get the icon if there is one
target.Icon = source.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName)
? source.Values[UmbracoExamineFieldNames.IconFieldName]
: Constants.Icons.DefaultIcon;
2019-03-26 10:39:50 +01:00
2020-01-28 17:07:06 +11:00
target.Name = source.Values.ContainsKey(UmbracoExamineFieldNames.NodeNameFieldName) ? source.Values[UmbracoExamineFieldNames.NodeNameFieldName] : "[no name]";
2019-03-26 10:39:50 +01:00
2021-06-23 12:46:50 -06:00
var culture = context.GetCulture()?.ToLowerInvariant();
if(culture.IsNullOrWhiteSpace() == false)
{
target.Name = source.Values.ContainsKey($"nodeName_{culture}") ? source.Values[$"nodeName_{culture}"] : target.Name;
}
if (source.Values.TryGetValue(UmbracoExamineFieldNames.UmbracoFileFieldName, out var umbracoFile) &&
umbracoFile.IsNullOrWhiteSpace() == false)
{
if (umbracoFile != null)
{
target.Name = $"{target.Name} ({umbracoFile})";
}
}
if (source.Values.ContainsKey(UmbracoExamineFieldNames.NodeKeyFieldName))
2019-03-26 10:39:50 +01:00
{
if (Guid.TryParse(source.Values[UmbracoExamineFieldNames.NodeKeyFieldName], out var key))
2017-07-19 13:42:47 +02:00
{
2019-03-26 10:39:50 +01:00
target.Key = key;
//need to set the UDI
if (source.Values.ContainsKey(ExamineFieldNames.CategoryFieldName))
2017-07-19 13:42:47 +02:00
{
switch (source.Values[ExamineFieldNames.CategoryFieldName])
2019-03-26 10:39:50 +01:00
{
case IndexTypes.Member:
target.Udi = new GuidUdi(Constants.UdiEntityType.Member, target.Key);
break;
case IndexTypes.Content:
target.Udi = new GuidUdi(Constants.UdiEntityType.Document, target.Key);
break;
case IndexTypes.Media:
target.Udi = new GuidUdi(Constants.UdiEntityType.Media, target.Key);
break;
}
2017-07-19 13:42:47 +02:00
}
2019-03-26 10:39:50 +01:00
}
}
2019-03-26 10:39:50 +01:00
if (source.Values.ContainsKey("parentID"))
{
2021-09-15 13:40:08 +02:00
if (int.TryParse(source.Values["parentID"], NumberStyles.Integer, CultureInfo.InvariantCulture,out var parentId))
2017-09-12 16:22:16 +02:00
{
2019-03-26 10:39:50 +01:00
target.ParentId = parentId;
}
else
{
target.ParentId = -1;
}
}
target.Path = source.Values.ContainsKey(UmbracoExamineFieldNames.IndexPathFieldName) ? source.Values[UmbracoExamineFieldNames.IndexPathFieldName] : "";
2019-03-26 10:39:50 +01:00
if (source.Values.ContainsKey(ExamineFieldNames.ItemTypeFieldName))
2019-03-26 10:39:50 +01:00
{
target.AdditionalData.Add("contentType", source.Values[ExamineFieldNames.ItemTypeFieldName]);
2019-03-26 10:39:50 +01:00
}
2017-07-19 13:42:47 +02:00
}
2018-09-26 16:27:34 +02:00
private static string? MapContentTypeIcon(IEntitySlim entity)
{
switch (entity)
{
case IMemberEntitySlim memberEntity:
return memberEntity.ContentTypeIcon;
case IContentEntitySlim contentEntity:
// NOTE: this case covers both content and media entities
return contentEntity.ContentTypeIcon;
}
return null;
}
2019-03-26 10:39:50 +01:00
private static string MapName(IEntitySlim source, MapperContext context)
2018-09-26 16:27:34 +02:00
{
2019-03-26 10:39:50 +01:00
if (!(source is DocumentEntitySlim doc))
return source.Name;
2018-09-26 16:27:34 +02:00
2019-03-26 10:39:50 +01:00
// invariant = only 1 name
if (!doc.Variations.VariesByCulture()) return source.Name;
2018-09-26 16:27:34 +02:00
2019-03-26 10:39:50 +01:00
// variant = depends on culture
var culture = context.GetCulture();
2018-09-26 16:27:34 +02:00
2019-03-26 10:39:50 +01:00
// if there's no culture here, the issue is somewhere else (UI, whatever) - throw!
if (culture == null)
//throw new InvalidOperationException("Missing culture in mapping options.");
// TODO: we should throw, but this is used in various places that won't set a culture yet
return source.Name;
2018-09-26 16:27:34 +02:00
2019-03-26 10:39:50 +01:00
// if we don't have a name for a culture, it means the culture is not available, and
// hey we should probably not be mapping it, but it's too late, return a fallback name
return doc.CultureNames.TryGetValue(culture, out var name) && !name.IsNullOrWhiteSpace() ? name : $"({source.Name})";
2018-09-26 16:27:34 +02:00
}
2017-07-19 13:42:47 +02:00
}
2017-07-20 11:21:28 +02:00
}