mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
- Adding fields list to part, has/get/weld methods for ContentPart.
- ContentPartDefinition.Field. --HG-- branch : dev
This commit is contained in:
@@ -3,11 +3,14 @@ using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.Utilities;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
public class ContentField : IContent {
|
||||
public virtual ContentItem ContentItem { get; set;}
|
||||
public class ContentField : ContentPart {
|
||||
public virtual ContentPart ContentPart { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ContentFieldDefinition Definition { get; set; }
|
||||
public IDictionary<string, string> Settings { get; private set; }
|
||||
|
||||
public new ContentPartDefinition PartDefinition { get { return ContentPart.PartDefinition; } }
|
||||
public ContentPartDefinition.Field PartFieldDefinition { get; set; }
|
||||
public ContentFieldDefinition FieldDefinition { get { return PartFieldDefinition.FieldDefinition; } }
|
||||
}
|
||||
|
||||
public class ContentField<TRecord> : ContentField {
|
||||
|
@@ -1,15 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.Utilities;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
public abstract class ContentPart : IContent {
|
||||
private readonly IList<ContentField> _fields;
|
||||
|
||||
public ContentPart() {
|
||||
_fields = new List<ContentField>();
|
||||
}
|
||||
|
||||
public virtual ContentItem ContentItem { get; set; }
|
||||
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
|
||||
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
|
||||
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
|
||||
|
||||
public IEnumerable<ContentField> ContentFields { get; set; }
|
||||
public IEnumerable<ContentField> Fields { get { return _fields; } }
|
||||
|
||||
|
||||
public bool Has(Type fieldType) {
|
||||
return fieldType == typeof(ContentItem) || _fields.Any(field => fieldType.IsAssignableFrom(field.GetType()));
|
||||
}
|
||||
|
||||
public IContent Get(Type fieldType) {
|
||||
if (fieldType == typeof(ContentItem))
|
||||
return this;
|
||||
return _fields.FirstOrDefault(field => fieldType.IsAssignableFrom(field.GetType()));
|
||||
}
|
||||
|
||||
public void Weld(ContentField field) {
|
||||
field.ContentPart = this;
|
||||
_fields.Add(field);
|
||||
}
|
||||
}
|
||||
|
||||
public class ContentPart<TRecord> : ContentPart {
|
||||
|
Reference in New Issue
Block a user