mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#16855: When adding a field you may no longer use spaces or special characters (breaks overrides and searching). Added a 'hint' to the UI for the format.
--HG-- branch : dev
This commit is contained in:
@@ -206,6 +206,7 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) {
|
public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) {
|
||||||
|
fieldName = SafeName(fieldName);
|
||||||
_contentDefinitionManager.AlterPartDefinition(partName, partBuilder =>
|
_contentDefinitionManager.AlterPartDefinition(partName, partBuilder =>
|
||||||
partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName))
|
partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName))
|
||||||
);
|
);
|
||||||
@@ -215,9 +216,8 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
_contentDefinitionManager.AlterPartDefinition(partName, typeBuilder => typeBuilder.RemoveField(fieldName));
|
_contentDefinitionManager.AlterPartDefinition(partName, typeBuilder => typeBuilder.RemoveField(fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
//gratuitously stolen from the RoutableService
|
private static string SafeName(string name) {
|
||||||
public string GenerateName(string name) {
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
if ( string.IsNullOrWhiteSpace(name) )
|
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
|
|
||||||
var dissallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""<>]+");
|
var dissallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""<>]+");
|
||||||
@@ -227,6 +227,12 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
|
|
||||||
if (name.Length > 128)
|
if (name.Length > 128)
|
||||||
name = name.Substring(0, 128);
|
name = name.Substring(0, 128);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//gratuitously stolen from the RoutableService
|
||||||
|
public string GenerateName(string name) {
|
||||||
|
name = SafeName(name);
|
||||||
|
|
||||||
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
|
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
|
||||||
name = VersionName(name);
|
name = VersionName(name);
|
||||||
|
@@ -4,8 +4,9 @@
|
|||||||
@using (Html.BeginFormAntiForgeryPost()) {
|
@using (Html.BeginFormAntiForgeryPost()) {
|
||||||
@Html.ValidationSummary()
|
@Html.ValidationSummary()
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="DisplayName">@T("Display Name")</label>
|
<label for="DisplayName">@T("Name")</label>
|
||||||
@Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium", autofocus = "autofocus"})
|
@Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium", autofocus = "autofocus"})
|
||||||
|
<span class="hint">@T("Use no spaces or special characters. For example, \"MyCustomField\"")</span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="FieldTypeName">@T("Field Type")</label>
|
<label for="FieldTypeName">@T("Field Type")</label>
|
||||||
|
Reference in New Issue
Block a user