Netcore: Migration of Model classes from Umbraco.Infrastructure to Core (#9404)
* Migrating more model, mapping and tree classes * Migrating files from Mapping dir without Newtonsoft dependency * Migrating files from PublishedContent and Editors dirs without Newtonsoft dependency + some more of the same kind * Migrating DataType class without the usage of Newtonsoft.Json and making the corresponding changes to all classes affected * Combining 3 ContentExtensions files into 1 * Refactoring from migrating ContentExtensions * Migrating more classes * Migrating ContentRepositoryExtensions - combining it with existing file in Umbraco.Core * removing Newtonsoft json dependency & migrating file. Adding partial migration of ConfigurationEditor, so PropertyTagsExtensions can be migrated * Migrating ContentTagsExtensions, and refactoring from changes in PropertyTagsExtensions * Changes that should be reverted once ConfigurationEditor class is fully migrated * VS couldn't find Composing, so build was failing. Removing the using solves the problem * Handling a single case for deserializing a subset of an input * Small changes and added tests to JsonNetSerializer Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Migrated ConfigurationEditor Signed-off-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
committed by
GitHub
parent
d498c1a2cd
commit
dd5f400cf3
89
src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs
Normal file
89
src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
public class MacroMapDefinition : IMapDefinition
|
||||
{
|
||||
private readonly ParameterEditorCollection _parameterEditors;
|
||||
private readonly ILogger<MacroMapDefinition> _logger;
|
||||
|
||||
public MacroMapDefinition(ParameterEditorCollection parameterEditors, ILogger<MacroMapDefinition> logger)
|
||||
{
|
||||
_parameterEditors = parameterEditors;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
{
|
||||
mapper.Define<IMacro, EntityBasic>((source, context) => new EntityBasic(), Map);
|
||||
mapper.Define<IMacro, MacroDisplay>((source, context) => new MacroDisplay(), Map);
|
||||
mapper.Define<IMacro, IEnumerable<MacroParameter>>((source, context) => context.MapEnumerable<IMacroProperty, MacroParameter>(source.Properties.Values));
|
||||
mapper.Define<IMacroProperty, MacroParameter>((source, context) => new MacroParameter(), Map);
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -Trashed -AdditionalData
|
||||
private static void Map(IMacro source, EntityBasic target, MapperContext context)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Icon = Constants.Icons.Macro;
|
||||
target.Id = source.Id;
|
||||
target.Key = source.Key;
|
||||
target.Name = source.Name;
|
||||
target.ParentId = -1;
|
||||
target.Path = "-1," + source.Id;
|
||||
target.Udi = Udi.Create(Constants.UdiEntityType.Macro, source.Key);
|
||||
}
|
||||
|
||||
private void Map(IMacro source, MacroDisplay target, MapperContext context)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Icon = Constants.Icons.Macro;
|
||||
target.Id = source.Id;
|
||||
target.Key = source.Key;
|
||||
target.Name = source.Name;
|
||||
target.ParentId = -1;
|
||||
target.Path = "-1," + source.Id;
|
||||
target.Udi = Udi.Create(Constants.UdiEntityType.Macro, source.Key);
|
||||
target.CacheByPage = source.CacheByPage;
|
||||
target.CacheByUser = source.CacheByMember;
|
||||
target.CachePeriod = source.CacheDuration;
|
||||
target.UseInEditor = source.UseInEditor;
|
||||
target.RenderInEditor = !source.DontRender;
|
||||
target.View = source.MacroSource;
|
||||
}
|
||||
// Umbraco.Code.MapAll -Value
|
||||
private void Map(IMacroProperty source, MacroParameter target, MapperContext context)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Name = source.Name;
|
||||
target.SortOrder = source.SortOrder;
|
||||
|
||||
//map the view and the config
|
||||
// we need to show the deprecated ones for backwards compatibility
|
||||
var paramEditor = _parameterEditors[source.EditorAlias]; // TODO: include/filter deprecated?!
|
||||
if (paramEditor == null)
|
||||
{
|
||||
//we'll just map this to a text box
|
||||
paramEditor = _parameterEditors[Constants.PropertyEditors.Aliases.TextBox];
|
||||
_logger.LogWarning("Could not resolve a parameter editor with alias {PropertyEditorAlias}, a textbox will be rendered in it's place", source.EditorAlias);
|
||||
}
|
||||
|
||||
target.View = paramEditor.GetValueEditor().View;
|
||||
|
||||
// sets the parameter configuration to be the default configuration editor's configuration,
|
||||
// ie configurationEditor.DefaultConfigurationObject, prepared for the value editor, ie
|
||||
// after ToValueEditor - important to use DefaultConfigurationObject here, because depending
|
||||
// on editors, ToValueEditor expects the actual strongly typed configuration - not the
|
||||
// dictionary thing returned by DefaultConfiguration
|
||||
|
||||
var configurationEditor = paramEditor.GetConfigurationEditor();
|
||||
target.Configuration = configurationEditor.ToValueEditor(configurationEditor.DefaultConfigurationObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user