mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
#16906: You can no longer add fields with an empty name
--HG-- branch : dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
_contentDefinitionService.AddFieldToPart(viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name);
|
||||
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();
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user