#18911: Fixing wrapper alternates. Shape type within wrapper templates should always be equal to the original shape type.

Work Item: 18911
This commit is contained in:
Piotr Szmyd
2013-11-05 05:41:06 +01:00
parent f567eb0ec4
commit d4d8e143cc
2 changed files with 13 additions and 13 deletions

View File

@@ -61,10 +61,13 @@ namespace Orchard.DisplayManagement.Implementation {
};
_shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger);
// if this shape is a wrapper - find alternates and binding sources for the wrapper, not the original type
var typeToLookup = shapeMetadata.WrapperType ?? shapeMetadata.Type;
// find base shape association using only the fundamental shape type.
// alternates that may already be registered do not affect the "displaying" event calls
ShapeBinding shapeBinding;
if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty<string>(), shapeTable, out shapeBinding)) {
if (TryGetDescriptorBinding(typeToLookup, Enumerable.Empty<string>(), shapeTable, out shapeBinding)) {
shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), Logger);
// copy all binding sources (all templates for this shape) in order to use them as Localization scopes
@@ -84,7 +87,7 @@ namespace Orchard.DisplayManagement.Implementation {
else {
// now find the actual binding to render, taking alternates into account
ShapeBinding actualBinding;
if ( TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding) ) {
if ( TryGetDescriptorBinding(typeToLookup, shapeMetadata.Alternates, shapeTable, out actualBinding) ) {
shape.Metadata.ChildContent = Process(actualBinding, shape, context);
}
else {
@@ -94,25 +97,21 @@ namespace Orchard.DisplayManagement.Implementation {
var wrappers = shape.Metadata.Wrappers;
var alternates = shape.Metadata.Alternates;
var bindingSources = shape.Metadata.BindingSources;
var currentWrapperType = shape.Metadata.WrapperType;
foreach (var wrapperType in wrappers) {
// clearing wrappers and alternates to prevent infinite loop
shape.Metadata.Wrappers = new List<string>();
shape.Metadata.Alternates = new List<string>();
shape.Metadata.BindingSources = new List<string>();
shape.Metadata.WrapperType = wrapperType;
// mutating current shape to the wrapper type, leaving all content unchanged
// (wrapper will have the same model as main template)
shape.Metadata.Type = wrapperType;
var newContext = new DisplayContext {
Display = context.Display,
Value = shape,
ViewContext = context.ViewContext,
ViewDataContainer = context.ViewDataContainer
};
shape.Metadata.ChildContent = Execute(newContext);
shape.Metadata.ChildContent = Execute(context);
}
shape.Metadata.WrapperType = currentWrapperType;
shape.Metadata.BindingSources = bindingSources;
shape.Metadata.Wrappers = wrappers;
shape.Metadata.Alternates = alternates;

View File

@@ -15,6 +15,7 @@ namespace Orchard.DisplayManagement.Shapes {
}
public string Type { get; set; }
public string WrapperType { get; set; }
public string DisplayType { get; set; }
public string Position { get; set; }
public string PlacementSource { get; set; }