mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#18439: Fixing ContentField and ContentPart automatic assignment to shapes
Work Item: 18439 --HG-- branch : 1.x
This commit is contained in:
@@ -12,6 +12,17 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
|
||||
public override void Apply(BuildDisplayContext context) {
|
||||
foreach (var result in _results) {
|
||||
|
||||
// copy the ContentPart which was used to render this result to its children
|
||||
// so they can assign it to the concrete shapes
|
||||
if (result.ContentPart == null && ContentPart != null) {
|
||||
result.ContentPart = ContentPart;
|
||||
}
|
||||
|
||||
if (result.ContentField == null && ContentField != null) {
|
||||
result.ContentField = ContentField;
|
||||
}
|
||||
|
||||
result.Apply(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,28 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
|
||||
DriverResult IContentFieldDriver.BuildDisplayShape(BuildDisplayContext context) {
|
||||
return Process(context.ContentItem, (part, field) => {
|
||||
context.ContentPart = part;
|
||||
context.ContentField = field;
|
||||
return Display(part, field, context.DisplayType, context.New);
|
||||
DriverResult result = Display(part, field, context.DisplayType, context.New);
|
||||
result.ContentPart = part;
|
||||
result.ContentField = field;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
DriverResult IContentFieldDriver.BuildEditorShape(BuildEditorContext context) {
|
||||
return Process(context.ContentItem, (part, field) => {
|
||||
context.ContentPart = part;
|
||||
context.ContentField = field;
|
||||
return Editor(part, field, context.New);
|
||||
DriverResult result = Editor(part, field, context.New);
|
||||
result.ContentPart = part;
|
||||
result.ContentField = field;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context) {
|
||||
return Process(context.ContentItem, (part, field) => {
|
||||
context.ContentPart = part;
|
||||
context.ContentField = field;
|
||||
return Editor(part, field, context.Updater, context.New);
|
||||
DriverResult result = Editor(part, field, context.Updater, context.New);
|
||||
result.ContentPart = part;
|
||||
result.ContentField = field;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,16 +129,6 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
|
||||
ShapeMetadata metadata = shape.Metadata;
|
||||
|
||||
// if no ContentField property has been set, assign it
|
||||
if (shape.ContentField == null) {
|
||||
shape.ContentField = ctx.ContentField;
|
||||
}
|
||||
|
||||
// if no ContentPart property has been set, assign it
|
||||
if (shape.ContentPart == null) {
|
||||
shape.ContentPart = ctx.ContentPart;
|
||||
}
|
||||
|
||||
// if no ContentItem property has been set, assign it
|
||||
if (shape.ContentItem == null) {
|
||||
shape.ContentItem = ctx.ContentItem;
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
return null;
|
||||
}
|
||||
|
||||
context.ContentPart = part;
|
||||
|
||||
return Display(part, context.DisplayType, context.New);
|
||||
DriverResult result = Display(part, context.DisplayType, context.New);
|
||||
result.ContentPart = part;
|
||||
return result;
|
||||
}
|
||||
|
||||
DriverResult IContentPartDriver.BuildEditor(BuildEditorContext context) {
|
||||
@@ -35,9 +35,9 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
return null;
|
||||
}
|
||||
|
||||
context.ContentPart = part;
|
||||
|
||||
return Editor(part, context.New);
|
||||
DriverResult result = Editor(part, context.New);
|
||||
result.ContentPart = part;
|
||||
return result;
|
||||
}
|
||||
|
||||
DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context) {
|
||||
@@ -47,9 +47,9 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
return null;
|
||||
}
|
||||
|
||||
context.ContentPart = part;
|
||||
|
||||
return Editor(part, context.Updater, context.New);
|
||||
DriverResult result = Editor(part, context.Updater, context.New);
|
||||
result.ContentPart = part;
|
||||
return result;
|
||||
}
|
||||
|
||||
void IContentPartDriver.Importing(ImportContentContext context) {
|
||||
@@ -107,11 +107,6 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
private static dynamic AddAlternates(dynamic shape, BuildShapeContext ctx) {
|
||||
ShapeMetadata metadata = shape.Metadata;
|
||||
|
||||
// if no ContentPart property has been set, assign it
|
||||
if (shape.ContentPart == null) {
|
||||
shape.ContentPart = ctx.ContentPart;
|
||||
}
|
||||
|
||||
// if no ContentItem property has been set, assign it
|
||||
if (shape.ContentItem == null) {
|
||||
shape.ContentItem = ctx.ContentItem;
|
||||
|
||||
@@ -35,6 +35,15 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
|
||||
dynamic parentShape = context.Shape;
|
||||
var newShape = _shapeBuilder(context);
|
||||
|
||||
if (ContentPart != null && newShape.ContentPart == null) {
|
||||
newShape.ContentPart = ContentPart;
|
||||
}
|
||||
|
||||
if (ContentField != null && newShape.ContentField == null) {
|
||||
newShape.ContentField = ContentField;
|
||||
}
|
||||
|
||||
ShapeMetadata newShapeMetadata = newShape.Metadata;
|
||||
newShapeMetadata.Prefix = _prefix;
|
||||
newShapeMetadata.DisplayType = displayType;
|
||||
|
||||
@@ -4,5 +4,8 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
public class DriverResult {
|
||||
public virtual void Apply(BuildDisplayContext context) { }
|
||||
public virtual void Apply(BuildEditorContext context) { }
|
||||
|
||||
public ContentPart ContentPart { get; set; }
|
||||
public ContentField ContentField { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
public dynamic Shape { get; private set; }
|
||||
public IContent Content { get; private set; }
|
||||
public ContentItem ContentItem { get; private set; }
|
||||
public ContentPart ContentPart { get; set; }
|
||||
public ContentField ContentField { get; set; }
|
||||
public dynamic New { get; private set; }
|
||||
public string GroupId { get; private set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user