Reverting shape wrappers

This commit is contained in:
Sebastien Ros
2013-11-08 12:08:23 -08:00
parent 494a57bb5a
commit ffdeec733a
4 changed files with 10 additions and 31 deletions

View File

@@ -56,15 +56,13 @@ namespace Orchard.DesignerTools.Services {
return; return;
} }
var type = displayedContext.ShapeMetadata.WrapperType ?? displayedContext.ShapeMetadata.Type;
// appends Url alternates to current ones // appends Url alternates to current ones
displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany( displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
alternate => new [] { alternate }.Union(_urlAlternates.Value.Select(a => alternate + "__url__" + a)) alternate => new [] { alternate }.Union(_urlAlternates.Value.Select(a => alternate + "__url__" + a))
).ToList(); ).ToList();
// appends [ShapeType]__url__[Url] alternates // appends [ShapeType]__url__[Url] alternates
displayedContext.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url => type + "__url__" + url) displayedContext.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
.Union(displayedContext.ShapeMetadata.Alternates) .Union(displayedContext.ShapeMetadata.Alternates)
.ToList(); .ToList();
}); });

View File

@@ -26,7 +26,7 @@ namespace Orchard.DesignerTools.Services {
var widgetPart = contentItem.As<WidgetPart>(); var widgetPart = contentItem.As<WidgetPart>();
if (widgetPart != null) { if (widgetPart != null) {
var zoneName = widgetPart.Zone; var zoneName = widgetPart.Zone;
var shapeName = displayedContext.ShapeMetadata.WrapperType ?? displayedContext.ShapeMetadata.Type; var shapeName = displayedContext.ShapeMetadata.Type;
var contentTypeName = contentItem.ContentType; var contentTypeName = contentItem.ContentType;
// Add 2 alternates for flexible widget shape naming: // Add 2 alternates for flexible widget shape naming:

View File

@@ -49,7 +49,7 @@ namespace Orchard.DisplayManagement.Implementation {
var shapeMetadata = shape.Metadata; var shapeMetadata = shape.Metadata;
// can't really cope with a shape that has no type information // can't really cope with a shape that has no type information
if (shapeMetadata == null || (string.IsNullOrEmpty(shapeMetadata.Type) && string.IsNullOrEmpty(shapeMetadata.WrapperType))) if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type))
return CoerceHtmlString(context.Value); return CoerceHtmlString(context.Value);
var workContext = _workContextAccessor.GetContext(context.ViewContext); var workContext = _workContextAccessor.GetContext(context.ViewContext);
@@ -61,13 +61,10 @@ namespace Orchard.DisplayManagement.Implementation {
}; };
_shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger); _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. // find base shape association using only the fundamental shape type.
// alternates that may already be registered do not affect the "displaying" event calls // alternates that may already be registered do not affect the "displaying" event calls
ShapeBinding shapeBinding; ShapeBinding shapeBinding;
if (TryGetDescriptorBinding(typeToLookup, Enumerable.Empty<string>(), shapeTable, out shapeBinding)) { if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty<string>(), shapeTable, out shapeBinding)) {
shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), Logger); 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 // copy all binding sources (all templates for this shape) in order to use them as Localization scopes
@@ -87,7 +84,7 @@ namespace Orchard.DisplayManagement.Implementation {
else { else {
// now find the actual binding to render, taking alternates into account // now find the actual binding to render, taking alternates into account
ShapeBinding actualBinding; ShapeBinding actualBinding;
if ( TryGetDescriptorBinding(typeToLookup, shapeMetadata.Alternates, shapeTable, out actualBinding) ) { if ( TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding) ) {
shape.Metadata.ChildContent = Process(actualBinding, shape, context); shape.Metadata.ChildContent = Process(actualBinding, shape, context);
} }
else { else {
@@ -95,28 +92,13 @@ namespace Orchard.DisplayManagement.Implementation {
} }
} }
// storing current shape metadata so it won't get altered by wrappers' display process foreach (var frameType in shape.Metadata.Wrappers) {
var wrappers = shape.Metadata.Wrappers; ShapeBinding frameBinding;
var alternates = shape.Metadata.Alternates; if (TryGetDescriptorBinding(frameType, Enumerable.Empty<string>(), shapeTable, out frameBinding)) {
var bindingSources = shape.Metadata.BindingSources; shape.Metadata.ChildContent = Process(frameBinding, shape, context);
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;
shape.Metadata.ChildContent = Execute(context);
} }
// restoring original shape metadata
shape.Metadata.WrapperType = currentWrapperType;
shape.Metadata.BindingSources = bindingSources;
shape.Metadata.Wrappers = wrappers;
shape.Metadata.Alternates = alternates;
var displayedContext = new ShapeDisplayedContext { var displayedContext = new ShapeDisplayedContext {
Shape = shape, Shape = shape,
ShapeMetadata = shape.Metadata, ShapeMetadata = shape.Metadata,

View File

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