Preventing Blueprints from being selectable as base elements.

This commit is contained in:
Sipke Schoorstra
2014-12-09 17:01:36 +01:00
parent 6340e504bc
commit 497f56c11f
2 changed files with 21 additions and 5 deletions

View File

@@ -57,7 +57,7 @@ namespace Orchard.Layouts.Controllers {
}
public ActionResult Browse() {
var categories = _elementManager.GetCategories(DescribeElementsContext.Empty).ToArray();
var categories = RemoveBlueprints(_elementManager.GetCategories(DescribeElementsContext.Empty)).ToArray();
var viewModel = new BrowseElementsViewModel {
Categories = categories
};
@@ -223,6 +223,21 @@ namespace Orchard.Layouts.Controllers {
return context;
}
private IEnumerable<CategoryDescriptor> RemoveBlueprints(IEnumerable<CategoryDescriptor> categories) {
foreach (var descriptor in categories) {
var d = new CategoryDescriptor(descriptor.Name, descriptor.DisplayName, descriptor.Description, descriptor.Position);
foreach (var element in descriptor.Elements) {
if (!element.StateBag.ContainsKey("Blueprint")) {
d.Elements.Add(element);
}
}
if(d.Elements.Any())
yield return d;
}
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -27,14 +27,14 @@ namespace Orchard.Layouts.Providers {
_isHarvesting = true;
var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();
var query =
var query =
from blueprint in blueprints
let describeContext = new DescribeElementsContext { Content = context.Content, CacheVaryParam = "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(
baseElement.Descriptor.ElementType,
blueprint.ElementTypeName,
baseElement.Descriptor.ElementType,
blueprint.ElementTypeName,
T(blueprint.ElementDisplayName),
GetCategory(blueprint)) {
EnableEditorDialog = false,
@@ -42,6 +42,7 @@ namespace Orchard.Layouts.Providers {
CreatingDisplay = creatingDisplayContext => CreatingDisplay(creatingDisplayContext, blueprint),
Display = displayContext => Displaying(displayContext, baseElement),
StateBag = new Dictionary<string, object> {
{"Blueprint", true},
{"ElementTypeName", baseElement.Descriptor.TypeName}
}
};