mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding support for fetching of element descriptors from the blue print element harvester.
The problem before this change was that the cache manager would cache an empty list of elements when trying to locate a blueprint element without specifying a content item. The VaryByParam property allows additional control over the cache key.
This commit is contained in:
@@ -93,7 +93,7 @@ namespace Orchard.Layouts.Framework.Display {
|
||||
var dictionary = new Dictionary<string, object> {
|
||||
{"Element", element},
|
||||
{"Elements", children},
|
||||
{"ContentItem", content.ContentItem}
|
||||
{"ContentItem", content != null ? content.ContentItem : default(ContentItem)}
|
||||
};
|
||||
|
||||
if (elementState != null) {
|
||||
|
@@ -28,8 +28,8 @@ namespace Orchard.Layouts.Providers {
|
||||
var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();
|
||||
|
||||
var query =
|
||||
from blueprint in blueprints
|
||||
let describeContext = DescribeElementsContext.Empty
|
||||
from blueprint in blueprints
|
||||
let describeContext = new DescribeElementsContext { Content = context.Content, CacheVaryParam = "Blueprints"}
|
||||
let baseElementDescriptor = _elementManager.Value.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName)
|
||||
let baseElement = _elementManager.Value.ActivateElement(baseElementDescriptor)
|
||||
select new ElementDescriptor(
|
||||
|
@@ -3,6 +3,8 @@ using Orchard.ContentManagement;
|
||||
namespace Orchard.Layouts.Services {
|
||||
public class DescribeElementsContext {
|
||||
public IContent Content { get; set; }
|
||||
public static DescribeElementsContext Empty = new DescribeElementsContext();
|
||||
public string CacheVaryParam { get; set; }
|
||||
|
||||
public static readonly DescribeElementsContext Empty = new DescribeElementsContext();
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@ namespace Orchard.Layouts.Services {
|
||||
|
||||
public IEnumerable<ElementDescriptor> DescribeElements(DescribeElementsContext context) {
|
||||
var contentType = context.Content != null ? context.Content.ContentItem.ContentType : default(string);
|
||||
var cacheKey = String.Format("LayoutElementTypes-{0}", contentType ?? "AnyType");
|
||||
var cacheKey = String.Format("LayoutElementTypes-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam);
|
||||
return _cacheManager.Get(cacheKey, acquireContext => {
|
||||
var harvesterContext = new HarvestElementsContext {
|
||||
Content = context.Content
|
||||
@@ -55,7 +55,7 @@ namespace Orchard.Layouts.Services {
|
||||
|
||||
public IEnumerable<CategoryDescriptor> GetCategories(DescribeElementsContext context) {
|
||||
var contentType = context.Content != null ? context.Content.ContentItem.ContentType : default(string);
|
||||
return _cacheManager.Get(String.Format("ElementCategories-{0}", contentType ?? "AnyType"), acquireContext => {
|
||||
return _cacheManager.Get(String.Format("ElementCategories-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam), acquireContext => {
|
||||
var elements = DescribeElements(context);
|
||||
var categoryDictionary = GetCategories();
|
||||
var categoryDescriptorDictionary = new Dictionary<string, CategoryDescriptor>();
|
||||
|
Reference in New Issue
Block a user