diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 10654534e..8a0eac55f 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -141,7 +141,7 @@ namespace Orchard.ContentTypes.Controllers { var viewModel = new AddPartsViewModel { Type = typeViewModel, - PartSelections = _contentDefinitionService.GetParts() + PartSelections = _contentDefinitionService.GetParts(false/*metadataPartsOnly*/) .Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name) && cpd.Settings.GetModel().Attachable) .Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName }) }; @@ -226,7 +226,7 @@ namespace Orchard.ContentTypes.Controllers { public ActionResult ListParts() { return View(new ListContentPartsViewModel { // only user-defined parts (not code as they are not configurable) - Parts = _contentDefinitionManager.ListPartDefinitions().Select(cpd => new EditPartViewModel(cpd)) + Parts = _contentDefinitionService.GetParts(true/*metadataPartsOnly*/) }); } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index dcf88ab96..e311baf60 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -152,15 +152,23 @@ namespace Orchard.ContentTypes.Services { _contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.RemovePart(partName)); } - public IEnumerable GetParts() { + public IEnumerable GetParts(bool metadataPartsOnly) { var typeNames = GetTypes().Select(ctd => ctd.Name); + // user-defined parts - var contentParts = _contentDefinitionManager.ListPartDefinitions().Select(cpd => new EditPartViewModel(cpd)); + // except for those parts with the same name as a type (implicit type's part or a mistake) + var userContentParts = _contentDefinitionManager + .ListPartDefinitions() + .Where(cpd => !typeNames.Contains(cpd.Name)) + .Select(cpd => new EditPartViewModel(cpd)); + // code-defined parts - var codeDefinedParts = _contentPartDrivers - .SelectMany(d => d.GetPartInfo().Where(cpd => !contentParts.Any(m => m.Name == cpd.PartName)).Select(cpi => new EditPartViewModel { Name = cpi.PartName })); - // all together now, except for those parts with the same name as a type (implicit type's part or a mistake) - return contentParts.Where(m => !typeNames.Contains(m.Name)).Union(codeDefinedParts).OrderBy(m => m.Name); + var codeDefinedParts = metadataPartsOnly ? + Enumerable.Empty() : + _contentPartDrivers.SelectMany(d => d.GetPartInfo().Where(cpd => !userContentParts.Any(m => m.Name == cpd.PartName)).Select(cpi => new EditPartViewModel { Name = cpi.PartName })); + + // Order by display name + return userContentParts.Union(codeDefinedParts).OrderBy(m => m.DisplayName); } public EditPartViewModel GetPart(string name) { @@ -183,9 +191,8 @@ namespace Orchard.ContentTypes.Services { name = VersionName(name); if (!String.IsNullOrEmpty(name)) { - var contentPartDefinition = new ContentPartDefinition(name); - _contentDefinitionManager.StorePartDefinition(contentPartDefinition); - return new EditPartViewModel(contentPartDefinition); + _contentDefinitionManager.AlterPartDefinition(name, builder => builder.Attachable()); + return new EditPartViewModel(_contentDefinitionManager.GetPartDefinition(name)); } return null; diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs index 44fc6b8ae..b6cb1d89c 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs @@ -15,7 +15,7 @@ namespace Orchard.ContentTypes.Services { void RemovePartFromType(string partName, string typeName); string GenerateName(string displayName); - IEnumerable GetParts(); + IEnumerable GetParts(bool metadataPartsOnly); EditPartViewModel GetPart(string name); EditPartViewModel AddPart(CreatePartViewModel partViewModel); void AlterPart(EditPartViewModel partViewModel, IUpdateModel updater);