#19734: Fixing Url Alternates creation order

The drawback is that Shape Tracer doesn't reflect which alternate is used
in the case on a url.

Work Item: 19734

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros 2013-07-11 17:29:48 -07:00
parent 4cf3db46ec
commit 181780cb6d
2 changed files with 21 additions and 20 deletions

View File

@ -14,6 +14,7 @@ Features:
Name: Url Alternates
Category: Designer
Description: Adds shape alternates for specific urls
Dependencies: Core
WidgetAlternates:
Name: Widget Alternates
Category: Designer

View File

@ -2,14 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;
using Orchard.Mvc;
namespace Orchard.DesignerTools.Services {
[OrchardFeature("UrlAlternates")]
public class UrlAlternatesFactory : ShapeFactoryEvents {
public class UrlAlternatesFactory : ShapeDisplayEvents {
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly Lazy<List<string>> _urlAlternates;
@ -44,29 +43,30 @@ namespace Orchard.DesignerTools.Services {
});
}
public override void Created(ShapeCreatedContext context) {
public override void Displaying(ShapeDisplayingContext context) {
IShape shape = context.Shape;
var shapeMetaData = shape.Metadata;
context.ShapeMetadata.OnDisplaying(displayedContext => {
if (_urlAlternates.Value == null || !_urlAlternates.Value.Any()) {
return;
}
if (_urlAlternates.Value == null || !_urlAlternates.Value.Any()) {
return;
}
// prevent applying alternate again, c.f. http://orchard.codeplex.com/workitem/18298
if (shapeMetaData.Alternates.Any(x => x.Contains("__url__"))) {
return;
}
// prevent applying alternate again, c.f. http://orchard.codeplex.com/workitem/18298
if(displayedContext.ShapeMetadata.Alternates.Any(x => x.Contains("__url__"))) {
return;
}
// appends Url alternates to current ones
shapeMetaData.Alternates = shapeMetaData.Alternates.SelectMany(
alternate => new [] { alternate }.Union(_urlAlternates.Value.Select(a => alternate + "__url__" + a))
).ToList();
// appends Url alternates to current ones
displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
alternate => new [] { alternate }.Union(_urlAlternates.Value.Select(a => alternate + "__url__" + a))
).ToList();
// appends [ShapeType]__url__[Url] alternates
displayedContext.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
.Union(displayedContext.ShapeMetadata.Alternates)
.ToList();
});
// appends [ShapeType]__url__[Url] alternates
shapeMetaData.Alternates = _urlAlternates.Value.Select(url => shapeMetaData.Type + "__url__" + url)
.Union(shapeMetaData.Alternates)
.ToList();
}
}
}