mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Updating the Common Body's editor to be more resilient to the TinyMCE module being disabled and allowing for any other editor to be used for any body part via the body flavor setting
- using a shape now for the template "Body_Editor" with an alternate added for the body flavor "Body_Editor__" + flavor (e.g. Body_Editor__html -> Body-Html.Editor in a case insensitive world) - html by default - tinymce provides an html editor template - template falls back to a textarea template work item: 16753 --HG-- branch : dev
This commit is contained in:
@@ -17,9 +17,6 @@ namespace Orchard.Core.Common.Drivers {
|
||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||
|
||||
private const string TemplateName = "Parts/Common.Body";
|
||||
//todo: change back - or to something better
|
||||
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
||||
private const string PlainTextEditorTemplate = "PlainTextEditor";
|
||||
|
||||
public BodyPartDriver(IOrchardServices services, IEnumerable<IHtmlFilter> htmlFilters) {
|
||||
_htmlFilters = htmlFilters;
|
||||
@@ -64,7 +61,7 @@ namespace Orchard.Core.Common.Drivers {
|
||||
private static BodyEditorViewModel BuildEditorViewModel(BodyPart part) {
|
||||
return new BodyEditorViewModel {
|
||||
BodyPart = part,
|
||||
TextEditorTemplate = GetFlavor(part) == "html" ? DefaultTextEditorTemplate : PlainTextEditorTemplate,
|
||||
EditorFlavor = GetFlavor(part),
|
||||
AddMediaPath = new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString()
|
||||
};
|
||||
}
|
||||
|
@@ -15,6 +15,11 @@ namespace Orchard.Core.Common {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
builder.Describe("Body_Editor")
|
||||
.OnDisplaying(displaying => {
|
||||
string flavor = displaying.Shape.EditorFlavor;
|
||||
displaying.ShapeMetadata.Alternates.Add("Body_Editor__" + flavor);
|
||||
});
|
||||
builder.Describe("Fields_Common_Text")
|
||||
.OnDisplaying(displaying => {
|
||||
string textFieldName = displaying.Shape.Name;
|
||||
|
@@ -14,7 +14,7 @@ namespace Orchard.Core.Common.ViewModels {
|
||||
set { BodyPart.Record.Format = value; }
|
||||
}
|
||||
|
||||
public string TextEditorTemplate { get; set; }
|
||||
public string EditorFlavor { get; set; }
|
||||
public string AddMediaPath { get; set; }
|
||||
}
|
||||
}
|
5
src/Orchard.Web/Core/Common/Views/Body.Editor.cshtml
Normal file
5
src/Orchard.Web/Core/Common/Views/Body.Editor.cshtml
Normal file
@@ -0,0 +1,5 @@
|
||||
@using Orchard.Utility.Extensions;
|
||||
@{
|
||||
string editorFlavor = Model.EditorFlavor;
|
||||
}
|
||||
@Html.TextArea("Text", (string)Model.Text, 25, 80, new { @class = editorFlavor.HtmlClassify() })
|
@@ -2,6 +2,6 @@
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
<fieldset>
|
||||
<label>@T("Body")</label>
|
||||
@Html.Partial("EditorTemplates/" + Model.TextEditorTemplate, Model)
|
||||
@Display.Body_Editor(Model)
|
||||
@Html.ValidationMessageFor(m => m.Text)
|
||||
</fieldset>
|
@@ -1,3 +0,0 @@
|
||||
@model BodyEditorViewModel
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
@Html.TextArea("Text", Model.Text, 25, 80, new { @class = Model.Format })
|
@@ -277,7 +277,7 @@
|
||||
<Content Include="Messaging\Views\EditorTemplates\Parts\MessageSettings.cshtml" />
|
||||
<Content Include="Common\Views\EditorTemplates\Fields\Common.Text.Edit.cshtml" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.cshtml" />
|
||||
<Content Include="Common\Views\EditorTemplates\PlainTextEditor.cshtml" />
|
||||
<Content Include="Common\Views\Body.Editor.cshtml" />
|
||||
<Content Include="Contents\Module.txt" />
|
||||
<Content Include="Contents\Views\Admin\CreatableTypeList.cshtml" />
|
||||
<Content Include="Localization\Styles\admin.css" />
|
||||
|
@@ -130,7 +130,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\EditorTemplates\TinyMceTextEditor.cshtml" />
|
||||
<Content Include="Views\Body-Html.Editor.cshtml" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@@ -1,5 +1,4 @@
|
||||
@model Orchard.Core.Common.ViewModels.BodyEditorViewModel
|
||||
@{
|
||||
@{
|
||||
Script.Require("TinyMce");
|
||||
}
|
||||
@using(Script.Foot()) {
|
||||
@@ -23,4 +22,4 @@
|
||||
//]]>
|
||||
</script>
|
||||
}
|
||||
@Html.TextArea("Text", Model.Text, 25, 80, new { @class = "html" })
|
||||
@Html.TextArea("Text", (string)Model.Text, 25, 80, new { @class = "html" })
|
Reference in New Issue
Block a user