#16906: You can no longer add fields with an empty name

--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-12-02 12:32:15 -08:00
parent cd5319dbd7
commit 4762b1d3f6
2 changed files with 15 additions and 6 deletions

View File

@@ -326,8 +326,8 @@ namespace Orchard.ContentTypes.Controllers {
if (partViewModel == null) {
//id passed in might be that of a type w/ no implicit field
if (typeViewModel != null) {
partViewModel = new EditPartViewModel { Name = typeViewModel.Name };
_contentDefinitionService.AddPart(new CreatePartViewModel { Name = partViewModel.Name });
partViewModel = new EditPartViewModel {Name = typeViewModel.Name};
_contentDefinitionService.AddPart(new CreatePartViewModel {Name = partViewModel.Name});
_contentDefinitionService.AddPartToType(partViewModel.Name, typeViewModel.Name);
}
else {
@@ -341,7 +341,14 @@ namespace Orchard.ContentTypes.Controllers {
return AddFieldTo(id);
}
try {
_contentDefinitionService.AddFieldToPart(viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name);
}
catch (Exception ex) {
Services.Notifier.Information(T("The \"{0}\" field was not added. {1}", viewModel.DisplayName, ex.Message));
Services.TransactionManager.Cancel();
return AddFieldTo(id);
}
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();

View File

@@ -210,9 +210,11 @@ namespace Orchard.ContentTypes.Services {
public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) {
fieldName = SafeName(fieldName);
_contentDefinitionManager.AlterPartDefinition(partName, partBuilder =>
partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName))
);
if (string.IsNullOrEmpty(fieldName)) {
throw new OrchardException(T("Fields must have a name containing no spaces or symbols."));
}
_contentDefinitionManager.AlterPartDefinition(partName,
partBuilder => partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName)));
}
public void RemoveFieldFromPart(string fieldName, string partName) {