mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Fixing FieldStorageEvents regarding common types
--HG-- branch : 1.x
This commit is contained in:
@@ -50,7 +50,7 @@ namespace Orchard.Core.Common.Drivers {
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Text", field.Value);
|
||||
}
|
||||
|
||||
public override void Describe(DescribeMembersContext context) {
|
||||
protected override void Describe(DescribeMembersContext context) {
|
||||
context
|
||||
.Member(null, typeof(string), T("Value"), T("The text associated with the field."));
|
||||
}
|
||||
|
@@ -43,6 +43,10 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
Process(context.ContentItem, (part, field) => Exported(part, field, context));
|
||||
}
|
||||
|
||||
void IContentFieldDriver.Describe(DescribeMembersContext context) {
|
||||
Describe(context);
|
||||
}
|
||||
|
||||
void Process(ContentItem item, Action<ContentPart, TField> effort) {
|
||||
var occurences = item.Parts.SelectMany(part => part.Fields.OfType<TField>().Select(field => new { part, field }));
|
||||
foreach (var occurence in occurences) {
|
||||
@@ -82,7 +86,7 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
protected virtual void Exporting(ContentPart part, TField field, ExportContentContext context) { }
|
||||
protected virtual void Exported(ContentPart part, TField field, ExportContentContext context) { }
|
||||
|
||||
public virtual void Describe(DescribeMembersContext context) { }
|
||||
protected virtual void Describe(DescribeMembersContext context) { }
|
||||
|
||||
public ContentShapeResult ContentShape(string shapeType, Func<dynamic> factory) {
|
||||
return ContentShapeImplementation(shapeType, null, ctx => factory());
|
||||
|
@@ -10,12 +10,15 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
|
||||
public class ContentFieldDriverCoordinator : ContentHandlerBase {
|
||||
private readonly IEnumerable<IContentFieldDriver> _drivers;
|
||||
private readonly IFieldStorageProviderSelector _fieldStorageProviderSelector;
|
||||
private readonly IEnumerable<IFieldStorageEvents> _fieldStorageEvents;
|
||||
|
||||
public ContentFieldDriverCoordinator(
|
||||
IEnumerable<IContentFieldDriver> drivers,
|
||||
IFieldStorageProviderSelector fieldStorageProviderSelector) {
|
||||
IFieldStorageProviderSelector fieldStorageProviderSelector,
|
||||
IEnumerable<IFieldStorageEvents> fieldStorageEvents) {
|
||||
_drivers = drivers;
|
||||
_fieldStorageProviderSelector = fieldStorageProviderSelector;
|
||||
_fieldStorageEvents = fieldStorageEvents;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
@@ -32,6 +35,9 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
|
||||
var storage = _fieldStorageProviderSelector
|
||||
.GetProvider(partFieldDefinition)
|
||||
.BindStorage(contentPart, partFieldDefinition);
|
||||
|
||||
storage = new FieldStorageEventStorage(storage, partFieldDefinition, contentPart, _fieldStorageEvents);
|
||||
|
||||
var field = fieldInfo.Factory(partFieldDefinition, storage);
|
||||
contentPart.Weld(field);
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.ContentManagement.FieldStorage
|
||||
{
|
||||
public class FieldStorageEventContext
|
||||
{
|
||||
namespace Orchard.ContentManagement.FieldStorage {
|
||||
public class FieldStorageEventContext {
|
||||
public IContent Content { get; set; }
|
||||
public string PartName { get; set; }
|
||||
public string FieldName { get; set; }
|
||||
@@ -13,8 +13,46 @@ namespace Orchard.ContentManagement.FieldStorage
|
||||
public Type ValueType { get; set; }
|
||||
}
|
||||
|
||||
public interface IFieldStorageEvents : IEventHandler
|
||||
{
|
||||
public interface IFieldStorageEvents : IEventHandler {
|
||||
void SetCalled(FieldStorageEventContext context);
|
||||
}
|
||||
|
||||
public class FieldStorageEventStorage : IFieldStorage {
|
||||
private readonly IFieldStorage _concreteStorage;
|
||||
private readonly ContentPartFieldDefinition _contentPartFieldDefinition;
|
||||
private readonly ContentPart _contentPart;
|
||||
private readonly IEnumerable<IFieldStorageEvents> _events;
|
||||
|
||||
public FieldStorageEventStorage(
|
||||
IFieldStorage concreteStorage,
|
||||
ContentPartFieldDefinition contentPartFieldDefinition,
|
||||
ContentPart contentPart,
|
||||
IEnumerable<IFieldStorageEvents> events) {
|
||||
_concreteStorage = concreteStorage;
|
||||
_contentPartFieldDefinition = contentPartFieldDefinition;
|
||||
_contentPart = contentPart;
|
||||
_events = events;
|
||||
}
|
||||
|
||||
public T Get<T>(string name) {
|
||||
return _concreteStorage.Get<T>(name);
|
||||
}
|
||||
|
||||
public void Set<T>(string name, T value) {
|
||||
_concreteStorage.Set(name, value);
|
||||
|
||||
var context = new FieldStorageEventContext {
|
||||
FieldName = _contentPartFieldDefinition.Name,
|
||||
PartName = _contentPart.PartDefinition.Name,
|
||||
Value = value,
|
||||
ValueName = name,
|
||||
ValueType = typeof(T),
|
||||
Content = _contentPart
|
||||
};
|
||||
|
||||
foreach (var fieldEvent in _events) {
|
||||
fieldEvent.SetCalled(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
public class InfosetStorageProvider : IFieldStorageProvider {
|
||||
private readonly IEnumerable<IFieldStorageEvents> _events;
|
||||
|
||||
public InfosetStorageProvider(IEnumerable<IFieldStorageEvents> events) {
|
||||
_events = events;
|
||||
}
|
||||
|
||||
public string ProviderName {
|
||||
get { return FieldStorageProviderSelector.DefaultProviderName; }
|
||||
}
|
||||
@@ -22,23 +15,7 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
|
||||
return new SimpleFieldStorage(
|
||||
(name, valueType) => Get(infosetPart.Infoset.Element, partName, fieldName, name),
|
||||
(name, valueType, value) => {
|
||||
Set(infosetPart.Infoset.Element, partName, fieldName, name, value);
|
||||
|
||||
var context = new FieldStorageEventContext {
|
||||
FieldName = partFieldDefinition.Name,
|
||||
PartName = contentPart.PartDefinition.Name,
|
||||
Value = value,
|
||||
ValueName = name,
|
||||
ValueType = valueType,
|
||||
Content = infosetPart
|
||||
};
|
||||
|
||||
foreach(var fieldEvent in _events) {
|
||||
fieldEvent.SetCalled(context);
|
||||
}
|
||||
}
|
||||
);
|
||||
(name, valueType, value) => Set(infosetPart.Infoset.Element, partName, fieldName, name, value));
|
||||
}
|
||||
|
||||
private static string Get(XElement element, string partName, string fieldName, string valueName) {
|
||||
|
Reference in New Issue
Block a user