-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/maxlengthsetting #8719
Merged
MatteoPiovanelli-Laser
merged 10 commits into
OrchardCMS:1.10.x
from
LaserSrl:feature/maxlengthsetting
Feb 21, 2024
Merged
Feature/maxlengthsetting #8719
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb52be4
added MaxLength setting for TextField
AgostiniAlessandro a46c2db
added MaxLength setting for TitlePart
AgostiniAlessandro c32beab
added missing files
AgostiniAlessandro a71707a
Removed where clause
AgostiniAlessandro c75ae51
changed title length to a constant and updated the recipe
AgostiniAlessandro 44a4b32
added comment to remind people to update the migration when they chan…
AgostiniAlessandro 905cc01
fixed hint text for title
AgostiniAlessandro 65a90d5
fixed maxLength initialization in TitlePartSettings.cshtml
AgostiniAlessandro 05511a8
MaxTitleLength constant is now Pascal case
AndreaPiovanelli e587fba
Correction on constant spelling in TitlePartSettings shape.
AndreaPiovanelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/Orchard.Web/Core/Common/Views/Body-Large.Editor.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/Orchard.Web/Core/Common/Views/Body-Small.Editor.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
@using Orchard.Utility.Extensions; | ||
@{ | ||
string editorFlavor = Model.EditorFlavor; | ||
var htmlAttributes = (Dictionary<string, object>)Model.HtmlAttributes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a "behavior" attached to this HtmlAttributes property that will initialize the dictionary automatically to prevent such tests. Can you try? |
||
|
||
var htmlAttributes = new Dictionary<string, object> { | ||
{"class", editorFlavor.HtmlClassify()} | ||
}; | ||
if (htmlAttributes == null) { | ||
htmlAttributes = new Dictionary<string, object> { | ||
{"class", editorFlavor.HtmlClassify()}}; | ||
|
||
} | ||
else { | ||
htmlAttributes["class"] = editorFlavor.HtmlClassify(); | ||
} | ||
|
||
if (Model.Required == true) { | ||
htmlAttributes["required"] = "required"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletions
19
src/Orchard.Web/Core/Common/Views/EditorTemplates/Fields.Common.Text.Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
@model Orchard.Core.Common.ViewModels.TextFieldDriverViewModel | ||
@{ | ||
var maxLength = Model.Settings.MaxLength > 0 ? Model.Settings.MaxLength.ToString() : ""; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.Text)" @if(Model.Settings.Required) { <text>class="required"</text> }>@Model.Field.DisplayName</label> | ||
<label for="@Html.FieldIdFor(m => m.Text)" @if (Model.Settings.Required) { <text> class="required" </text> }>@Model.Field.DisplayName</label> | ||
@if (String.IsNullOrWhiteSpace(Model.Settings.Flavor)) { | ||
@(Model.Settings.Required ? Html.TextBoxFor(m => m.Text, new {@class = "text", required = "required"}) : Html.TextBoxFor(m => m.Text, new {@class = "text"})) | ||
@(Model.Settings.Required | ||
? Html.TextBoxFor(m => m.Text, new {@class = "text", required = "required", maxlength = maxLength}) | ||
: Html.TextBoxFor(m => m.Text, new {@class = "text", maxlength = maxLength })) | ||
@Html.ValidationMessageFor(m => m.Text) | ||
} | ||
else { | ||
@Display.Body_Editor(Text: Model.Text, EditorFlavor: Model.Settings.Flavor, Required: Model.Settings.Required, ContentItem: Model.ContentItem, Field: Model.Field) | ||
|
||
var htmlAttributes = new Dictionary<string, object> { | ||
{"maxlength", maxLength} | ||
}; | ||
|
||
@Display.Body_Editor(Text: Model.Text, EditorFlavor: Model.Settings.Flavor, Required: Model.Settings.Required, | ||
ContentItem: Model.ContentItem, Field: Model.Field, HtmlAttributes: htmlAttributes) | ||
} | ||
@if (HasText(Model.Settings.Hint)) { | ||
<span class="hint">@Model.Settings.Hint</span> | ||
<span class="hint">@Model.Settings.Hint</span> | ||
} | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace Orchard.Core.Title.Settings { | ||
|
||
|
||
public class TitlePartSettings { | ||
// Whenever this constant is changed a new migration step must be created to update the length of the field on the DB | ||
public const int MaxTitleLength = 1024; | ||
[Range(0, MaxTitleLength)] | ||
[DisplayName("Maximum Length")] | ||
public int MaxLength {get; set;} | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Orchard.Web/Core/Title/Settings/TitlePartSettingsEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using Orchard.ContentManagement; | ||
using Orchard.ContentManagement.MetaData; | ||
using Orchard.ContentManagement.MetaData.Builders; | ||
using Orchard.ContentManagement.MetaData.Models; | ||
using Orchard.ContentManagement.ViewModels; | ||
|
||
namespace Orchard.Core.Title.Settings { | ||
public class TitlePartSettingsEvents : ContentDefinitionEditorEventsBase { | ||
|
||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) { | ||
if (definition.PartDefinition.Name != "TitlePart") { | ||
yield break; | ||
} | ||
|
||
var settings = definition | ||
.Settings | ||
.GetModel<TitlePartSettings>() | ||
?? new TitlePartSettings(); | ||
|
||
yield return DefinitionTemplate(settings); | ||
} | ||
|
||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { | ||
|
||
if (builder.Name != "TitlePart") { | ||
yield break; | ||
} | ||
|
||
var model = new TitlePartSettings(); | ||
|
||
if (updateModel.TryUpdateModel(model, "TitlePartSettings", null, null)) { | ||
builder.WithSetting("TitlePartSettings.MaxLength", model.MaxLength.ToString()); | ||
|
||
} | ||
yield return DefinitionTemplate(model); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Orchard.Web/Core/Title/Views/DefinitionTemplates/TitlePartSettings.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@using Orchard.Core.Title.Settings; | ||
@model TitlePartSettings | ||
@{ | ||
var maxLength = TitlePartSettings.MaxTitleLength; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.MaxLength)">@T("Maximum length")</label> | ||
@Html.EditorFor(m => m.MaxLength, new { htmlAttributes = new { min = 0, max = maxLength } }) | ||
<span class="hint">@T("Maximum length allowed for the title. Setting the value to 0 means the maximum allowed length is {0} characters.", maxLength)</span> | ||
@Html.ValidationMessageFor(m => m.MaxLength) | ||
</fieldset> |
10 changes: 7 additions & 3 deletions
10
src/Orchard.Web/Core/Title/Views/EditorTemplates/Parts.Title.TitlePart.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
@model Orchard.Core.Title.Models.TitlePart | ||
@using Orchard.Core.Title.Settings | ||
@model Orchard.Core.Title.Models.TitlePart | ||
@{ | ||
var maxLength = Model.Settings.GetModel<TitlePartSettings>().MaxLength > 0 ? Model.Settings.GetModel<TitlePartSettings>().MaxLength.ToString() : ""; | ||
} | ||
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => m.Title)" class="required">@T("Title")</label> | ||
@Html.TextBoxFor(m => m.Title, new { @class = "text large", autofocus = "autofocus" }) | ||
<label for="@Html.FieldIdFor(m => m.Title)" class="required">@T("Title")</label> | ||
@Html.TextBoxFor(m => m.Title, new { @class = "text large", autofocus = "autofocus", maxlength = maxLength }) | ||
<span class="hint">@T("You must provide a title for this content item")</span> | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to set the attributes even if Model.HtmlAttributes is null, meaning don't check for it, just assign it and see if that works (some magic we made in Orchard1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, it doesn't work.
Anyway I found a bug introduced in the last commit and I fixed it and tested everything from scratch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because the existing property on the shapes is named
Attributes
. Can you try to use this one and even doing something likeModel.Attributes["required"] = "required"
for instance?And it also already has a
IList<string> Classes
property which isn't null.