Fixes: U4-7639 Misleading message on creating first document type and click on "compositions"
Added in FirstContentType property on object returned from GetEmpty to indicate whether this is the first content type being created or not (different error messages in backoffice).
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
Mapper.Initialize(configuration =>
|
||||
{
|
||||
//initialize our content type mapper
|
||||
var mapper = new ContentTypeModelMapper(new Lazy<PropertyEditorResolver>(() => _propertyEditorResolver.Object));
|
||||
var mapper = new ContentTypeModelMapper(new Lazy<PropertyEditorResolver>(() => _propertyEditorResolver.Object), new Lazy<IContentTypeService>(() => appContext.Services.ContentTypeService));
|
||||
mapper.ConfigureMappings(configuration, appContext);
|
||||
var entityMapper = new EntityModelMapper();
|
||||
entityMapper.ConfigureMappings(configuration, appContext);
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
|
||||
[DataContract(Name = "contentType", Namespace = "")]
|
||||
public class ContentTypeDisplay : ContentTypeCompositionDisplay
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
|
||||
[DataContract(Name = "contentType", Namespace = "")]
|
||||
public class ContentTypeDisplay : ContentTypeCompositionDisplay
|
||||
{
|
||||
public ContentTypeDisplay()
|
||||
{
|
||||
//initialize collections so at least their never null
|
||||
AllowedTemplates = new List<EntityBasic>();
|
||||
}
|
||||
|
||||
//name, alias, icon, thumb, desc, inherited from the content type
|
||||
|
||||
// Templates
|
||||
[DataMember(Name = "allowedTemplates")]
|
||||
public IEnumerable<EntityBasic> AllowedTemplates { get; set; }
|
||||
|
||||
[DataMember(Name = "defaultTemplate")]
|
||||
public EntityBasic DefaultTemplate { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
public ContentTypeDisplay()
|
||||
{
|
||||
//initialize collections so at least their never null
|
||||
AllowedTemplates = new List<EntityBasic>();
|
||||
}
|
||||
|
||||
//name, alias, icon, thumb, desc, inherited from the content type
|
||||
|
||||
// Templates
|
||||
[DataMember(Name = "allowedTemplates")]
|
||||
public IEnumerable<EntityBasic> AllowedTemplates { get; set; }
|
||||
|
||||
[DataMember(Name = "defaultTemplate")]
|
||||
public EntityBasic DefaultTemplate { get; set; }
|
||||
|
||||
[DataMember(Name = "firstContentType")]
|
||||
public bool FirstContentType { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper.Internal;
|
||||
using Umbraco.Core.Services;
|
||||
using Property = umbraco.NodeFactory.Property;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
@@ -19,17 +20,20 @@ namespace Umbraco.Web.Models.Mapping
|
||||
internal class ContentTypeModelMapper : MapperConfiguration
|
||||
{
|
||||
private readonly Lazy<PropertyEditorResolver> _propertyEditorResolver;
|
||||
private readonly Lazy<IContentTypeService> _contentTypeService;
|
||||
|
||||
//default ctor
|
||||
public ContentTypeModelMapper()
|
||||
{
|
||||
_propertyEditorResolver = new Lazy<PropertyEditorResolver>(() => PropertyEditorResolver.Current);
|
||||
_contentTypeService = new Lazy<IContentTypeService>(() => ApplicationContext.Current.Services.ContentTypeService);
|
||||
}
|
||||
|
||||
//ctor can be used for testing
|
||||
public ContentTypeModelMapper(Lazy<PropertyEditorResolver> propertyEditorResolver)
|
||||
public ContentTypeModelMapper(Lazy<PropertyEditorResolver> propertyEditorResolver, Lazy<IContentTypeService> contentTypeService)
|
||||
{
|
||||
_propertyEditorResolver = propertyEditorResolver;
|
||||
_contentTypeService = contentTypeService;
|
||||
}
|
||||
|
||||
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
|
||||
@@ -114,6 +118,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(dto => dto.AllowedTemplates, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.DefaultTemplate, expression => expression.Ignore())
|
||||
.ForMember(display => display.Notifications, expression => expression.Ignore())
|
||||
.ForMember(x => x.FirstContentType, exp => exp.ResolveUsing(new FirstContentTypeResolver(_contentTypeService)))
|
||||
.AfterMap((source, dest) =>
|
||||
{
|
||||
//sync templates
|
||||
@@ -176,6 +181,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.MapBaseContentTypeSaveToDisplay()
|
||||
.ForMember(dto => dto.AllowedTemplates, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.DefaultTemplate, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.FirstContentType, exp => exp.Ignore())
|
||||
.AfterMap((source, dest) =>
|
||||
{
|
||||
//sync templates
|
||||
|
||||
24
src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs
Normal file
24
src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class FirstContentTypeResolver : ValueResolver<IContentType, bool>
|
||||
{
|
||||
private readonly Lazy<IContentTypeService> _contentTypeService;
|
||||
|
||||
public FirstContentTypeResolver(Lazy<IContentTypeService> contentTypeService)
|
||||
{
|
||||
_contentTypeService = contentTypeService;
|
||||
}
|
||||
|
||||
protected override bool ResolveCore(IContentType source)
|
||||
{
|
||||
var contentTypes = _contentTypeService.Value.GetAllContentTypes();
|
||||
return contentTypes.Any() == false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,6 +309,7 @@
|
||||
<Compile Include="Models\ContentEditing\PropertyTypeBasic.cs" />
|
||||
<Compile Include="Models\ContentEditing\SimpleNotificationModel.cs" />
|
||||
<Compile Include="Models\Mapping\ContentTypeModelMapperExtensions.cs" />
|
||||
<Compile Include="Models\Mapping\FirstContentTypeResolver.cs" />
|
||||
<Compile Include="Models\PublishedContentWithKeyBase.cs" />
|
||||
<Compile Include="Mvc\IRenderController.cs" />
|
||||
<Compile Include="Mvc\RenderIndexActionSelectorAttribute.cs" />
|
||||
|
||||
Reference in New Issue
Block a user