mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 12:03:16 +08:00
Fixed ContentFieldHarvester when NULL Content
The content field harvester throws an error when the LayoutEditor is rendered without having a content item as the context (BluePrints, for example). The previous code would fall back to simply enumerating all fields of all parts to make available all content fields as elements. However, the content field elements can't render these fields without having a proper content item as context, so it would fail with an exception. There are scenarios where one might still want to be able to add content field elements on the canvas even when there is no current content item (to create template layouts for example). But to support this, we need to figure out what we want to render if we can;t actually render the content field at design time. Perhaps a simplified representation would suffice in this scenario. To be discussed. Removing the broken feature for now.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
@@ -52,20 +52,18 @@ namespace Orchard.Layouts.Providers {
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<ContentPartDefinition, ContentPartFieldDefinition>> GetContentFieldTuples(HarvestElementsContext context) {
|
||||
var contentTypeDefinition = context.Content != null
|
||||
? _contentDefinitionManager.Value.GetTypeDefinition(context.Content.ContentItem.ContentType)
|
||||
: default(ContentTypeDefinition);
|
||||
|
||||
var parts = contentTypeDefinition != null
|
||||
? contentTypeDefinition.Parts.Select(x => x.PartDefinition)
|
||||
: _contentDefinitionManager.Value.ListPartDefinitions();
|
||||
// If there is no content item provided as context, there are no fields made available.
|
||||
if (context.Content == null)
|
||||
return Enumerable.Empty<Tuple<ContentPartDefinition, ContentPartFieldDefinition>>();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionManager.Value.GetTypeDefinition(context.Content.ContentItem.ContentType);
|
||||
var parts = contentTypeDefinition.Parts.Select(x => x.PartDefinition);
|
||||
var fields = parts.SelectMany(part => part.Fields.Select(field => Tuple.Create(part, field)));
|
||||
|
||||
// TODO: Each module should be able to tell which fields are supported as droppable elements.
|
||||
var blackList = new string[0];
|
||||
|
||||
return fields.Where(t => blackList.All(x => t.Item2.FieldDefinition.Name != x));
|
||||
return fields.Where(t => blackList.All(x => t.Item2.FieldDefinition.Name != x)).ToList();
|
||||
}
|
||||
|
||||
private void Displaying(ElementDisplayingContext context) {
|
||||
@@ -88,4 +86,4 @@ namespace Orchard.Layouts.Providers {
|
||||
context.ElementShape.ContentField = contentFieldShape;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user