mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#21391: Fixed layout and shape rendering from background processes.
This commit is contained in:
@@ -13,14 +13,14 @@ namespace Orchard.Layouts.Services {
|
||||
// Consider combining this class with DefaultContentDisplay to reuse shared code, for example by inheriting from a common base class.
|
||||
public abstract class ContentDisplayBase : Component {
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly Lazy<IShapeTableLocator> _shapeTableLocator;
|
||||
private readonly Lazy<IShapeTableLocator> _shapeTableLocator;
|
||||
private readonly RequestContext _requestContext;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
protected ContentDisplayBase(
|
||||
IShapeFactory shapeFactory,
|
||||
Lazy<IShapeTableLocator> shapeTableLocator,
|
||||
Lazy<IShapeTableLocator> shapeTableLocator,
|
||||
RequestContext requestContext,
|
||||
IVirtualPathProvider virtualPathProvider,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
@@ -109,9 +109,9 @@ namespace Orchard.Layouts.Services {
|
||||
private void BindPlacement(BuildShapeContext context, string displayType, string stereotype) {
|
||||
context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {
|
||||
var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);
|
||||
var theme = workContext.CurrentTheme;
|
||||
var shapeTable = _shapeTableLocator.Value.Lookup(theme.Id);
|
||||
var request = _requestContext.HttpContext.Request;
|
||||
var shapeTable = workContext.HttpContext != null
|
||||
? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
|
||||
: _shapeTableLocator.Value.Lookup(null);
|
||||
|
||||
ShapeDescriptor descriptor;
|
||||
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
|
||||
|
@@ -13,7 +13,7 @@ namespace Orchard.ContentManagement {
|
||||
public class DefaultContentDisplay : IContentDisplay {
|
||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly Lazy<IShapeTableLocator> _shapeTableLocator;
|
||||
private readonly Lazy<IShapeTableLocator> _shapeTableLocator;
|
||||
|
||||
private readonly RequestContext _requestContext;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
@@ -22,7 +22,7 @@ namespace Orchard.ContentManagement {
|
||||
public DefaultContentDisplay(
|
||||
Lazy<IEnumerable<IContentHandler>> handlers,
|
||||
IShapeFactory shapeFactory,
|
||||
Lazy<IShapeTableLocator> shapeTableLocator,
|
||||
Lazy<IShapeTableLocator> shapeTableLocator,
|
||||
RequestContext requestContext,
|
||||
IVirtualPathProvider virtualPathProvider,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
@@ -74,13 +74,13 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
// adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
|
||||
((IShape)itemShape).Metadata.Alternates.Add(actualShapeType + "__" + content.ContentItem.ContentType);
|
||||
|
||||
|
||||
var context = new BuildEditorContext(itemShape, content, groupId, _shapeFactory);
|
||||
BindPlacement(context, null, stereotype);
|
||||
|
||||
_handlers.Value.Invoke(handler => handler.BuildEditor(context), Logger);
|
||||
|
||||
|
||||
|
||||
return context.Shape;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Orchard.ContentManagement {
|
||||
BindPlacement(context, null, stereotype);
|
||||
|
||||
_handlers.Value.Invoke(handler => handler.UpdateEditor(context), Logger);
|
||||
|
||||
|
||||
return context.Shape;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Orchard.ContentManagement {
|
||||
Stereotype = stereotype,
|
||||
DisplayType = displayType,
|
||||
Differentiator = differentiator,
|
||||
Path = GetPath()
|
||||
Path = GetPath()
|
||||
};
|
||||
|
||||
// define which location should be used if none placement is hit
|
||||
@@ -154,8 +154,7 @@ namespace Orchard.ContentManagement {
|
||||
/// <summary>
|
||||
/// Gets the current app-relative path, i.e. ~/my-blog/foo.
|
||||
/// </summary>
|
||||
private string GetPath()
|
||||
{
|
||||
private string GetPath() {
|
||||
return VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path));
|
||||
}
|
||||
}
|
||||
|
@@ -169,6 +169,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
context.ViewContext.ViewData = new ViewDataDictionary(context.Value);
|
||||
context.ViewContext.TempData = new TempDataDictionary();
|
||||
context.ViewContext.View = viewResult.View;
|
||||
context.ViewContext.RouteData = controllerContext.RouteData;
|
||||
context.ViewContext.RequestContext.RouteData = controllerContext.RouteData;
|
||||
viewResult.View.Render(context.ViewContext, sw);
|
||||
viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
|
||||
return new HtmlString(sw.GetStringBuilder().ToString());
|
||||
|
@@ -83,7 +83,7 @@ namespace Orchard.Mvc {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// standin context for background tasks.
|
||||
/// Standin context for background tasks.
|
||||
/// </summary>
|
||||
class HttpContextPlaceholder : HttpContextBase {
|
||||
private readonly Lazy<string> _baseUrl;
|
||||
@@ -124,6 +124,12 @@ namespace Orchard.Mvc {
|
||||
public override string ApplyAppPathModifier(string virtualPath) {
|
||||
return virtualPath;
|
||||
}
|
||||
|
||||
public override HttpCookieCollection Cookies {
|
||||
get {
|
||||
return new HttpCookieCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -158,7 +164,7 @@ namespace Orchard.Mvc {
|
||||
|
||||
public override NameValueCollection Headers {
|
||||
get {
|
||||
return new NameValueCollection {{"Host", _uri.Authority}};
|
||||
return new NameValueCollection { { "Host", _uri.Authority } };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,10 +190,44 @@ namespace Orchard.Mvc {
|
||||
}
|
||||
}
|
||||
|
||||
public override HttpCookieCollection Cookies {
|
||||
get {
|
||||
return new HttpCookieCollection();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsLocal {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override string Path {
|
||||
get { return "/"; }
|
||||
}
|
||||
|
||||
public override string UserAgent {
|
||||
get {
|
||||
return "Placeholder";
|
||||
}
|
||||
}
|
||||
|
||||
public override HttpBrowserCapabilitiesBase Browser {
|
||||
get {
|
||||
return new HttpBrowserCapabilitiesPlaceholder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HttpBrowserCapabilitiesPlaceholder : HttpBrowserCapabilitiesBase {
|
||||
public override string this[string key] {
|
||||
get {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsMobileDevice { get { return false; } }
|
||||
public override string Browser { get { return "Placeholder"; } }
|
||||
public override bool Cookies { get { return true; } }
|
||||
public override ArrayList Browsers { get { return new ArrayList(); } }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user