Changed IContentType on IContent to a more simple class with lesser properties
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Umbraco.Core.Models
|
||||
[DataContract(IsReference = true)]
|
||||
public class Content : ContentBase, IContent
|
||||
{
|
||||
private IContentType _contentType;
|
||||
private ISimpleContentType _contentType;
|
||||
private ITemplate _template;
|
||||
private ContentScheduleCollection _schedule;
|
||||
private bool _published;
|
||||
@@ -48,7 +48,8 @@ namespace Umbraco.Core.Models
|
||||
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string culture = null)
|
||||
: base(name, parent, contentType, properties, culture)
|
||||
{
|
||||
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
|
||||
if (contentType == null) throw new ArgumentNullException(nameof(contentType));
|
||||
_contentType = new SimpleContentType(contentType);
|
||||
_publishedState = PublishedState.Unpublished;
|
||||
PublishedVersionId = 0;
|
||||
}
|
||||
@@ -75,7 +76,8 @@ namespace Umbraco.Core.Models
|
||||
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null)
|
||||
: base(name, parentId, contentType, properties, culture)
|
||||
{
|
||||
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
|
||||
if (contentType == null) throw new ArgumentNullException(nameof(contentType));
|
||||
_contentType = new SimpleContentType(contentType);
|
||||
_publishedState = PublishedState.Unpublished;
|
||||
PublishedVersionId = 0;
|
||||
}
|
||||
@@ -181,7 +183,7 @@ namespace Umbraco.Core.Models
|
||||
/// Gets the ContentType used by this content object
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IContentType ContentType => _contentType;
|
||||
public ISimpleContentType ContentType => _contentType;
|
||||
|
||||
/// <inheritdoc />
|
||||
[IgnoreDataMember]
|
||||
@@ -423,7 +425,7 @@ namespace Umbraco.Core.Models
|
||||
public void ChangeContentType(IContentType contentType)
|
||||
{
|
||||
ContentTypeId = contentType.Id;
|
||||
_contentType = contentType;
|
||||
_contentType = new SimpleContentType(contentType);
|
||||
ContentTypeBase = contentType;
|
||||
Properties.EnsurePropertyTypes(PropertyTypes);
|
||||
|
||||
@@ -442,7 +444,7 @@ namespace Umbraco.Core.Models
|
||||
if(clearProperties)
|
||||
{
|
||||
ContentTypeId = contentType.Id;
|
||||
_contentType = contentType;
|
||||
_contentType = new SimpleContentType(contentType);
|
||||
ContentTypeBase = contentType;
|
||||
Properties.EnsureCleanPropertyTypes(PropertyTypes);
|
||||
|
||||
@@ -460,8 +462,6 @@ namespace Umbraco.Core.Models
|
||||
|
||||
if (Template != null)
|
||||
Template.ResetDirtyProperties(rememberDirty);
|
||||
if (ContentType != null)
|
||||
ContentType.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
// take care of the published state
|
||||
_publishedState = _published ? PublishedState.Published : PublishedState.Unpublished;
|
||||
@@ -502,7 +502,9 @@ namespace Umbraco.Core.Models
|
||||
var clonedContent = (Content)clone;
|
||||
|
||||
//need to manually clone this since it's not settable
|
||||
clonedContent._contentType = (IContentType) ContentType.DeepClone();
|
||||
clonedContent._contentType = ContentType;
|
||||
|
||||
|
||||
|
||||
//if culture infos exist then deal with event bindings
|
||||
if (clonedContent._publishInfos != null)
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the content type of this content.
|
||||
/// </summary>
|
||||
IContentType ContentType { get; }
|
||||
ISimpleContentType ContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a culture is published.
|
||||
|
||||
76
src/Umbraco.Core/Models/ISimpleContentType.cs
Normal file
76
src/Umbraco.Core/Models/ISimpleContentType.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a ContentType, which Content is based on
|
||||
/// </summary>
|
||||
public interface ISimpleContentType
|
||||
{
|
||||
string Alias { get; }
|
||||
int Id { get; }
|
||||
ITemplate DefaultTemplate { get; }
|
||||
ContentVariation Variations { get; }
|
||||
string Icon { get; }
|
||||
bool IsContainer { get; }
|
||||
string Name { get; }
|
||||
bool AllowedAsRoot { get; }
|
||||
bool SupportsPropertyVariation(string culture, string s, bool b);
|
||||
}
|
||||
|
||||
public class SimpleContentType : ISimpleContentType
|
||||
{
|
||||
public SimpleContentType(IContentType contentType)
|
||||
{
|
||||
Id = contentType.Id;
|
||||
Alias = contentType.Alias;
|
||||
DefaultTemplate = contentType.DefaultTemplate;
|
||||
Variations = contentType.Variations;
|
||||
Icon = contentType.Icon;
|
||||
IsContainer = contentType.IsContainer;
|
||||
Icon = contentType.Icon;
|
||||
Name = contentType.Name;
|
||||
AllowedAsRoot = contentType.AllowedAsRoot;
|
||||
}
|
||||
|
||||
public string Alias { get; }
|
||||
public int Id { get; }
|
||||
public ITemplate DefaultTemplate { get; }
|
||||
public ContentVariation Variations { get; }
|
||||
public string Icon { get; }
|
||||
public bool IsContainer { get; }
|
||||
public string Name { get; }
|
||||
public bool AllowedAsRoot { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsPropertyVariation(string culture, string segment, bool wildcards = false)
|
||||
{
|
||||
// non-exact validation: can accept a 'null' culture if the property type varies
|
||||
// by culture, and likewise for segment
|
||||
// wildcard validation: can accept a '*' culture or segment
|
||||
return Variations.ValidateVariation(culture, segment, false, wildcards, false);
|
||||
}
|
||||
|
||||
|
||||
protected bool Equals(SimpleContentType other)
|
||||
{
|
||||
return string.Equals(Alias, other.Alias) && Id == other.Id;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((SimpleContentType) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((Alias != null ? Alias.GetHashCode() : 0) * 397) ^ Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user