Skip to content

Commit

Permalink
Merge pull request #230 from Lombiq/issue/LMBQ-276
Browse files Browse the repository at this point in the history
LMBQ-276: Improving WithEditor
  • Loading branch information
MZole authored Dec 30, 2023
2 parents 38cfe73 + 8a0a867 commit e45b4ae
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.ComponentModel;

namespace Lombiq.HelpfulLibraries.OrchardCore.Contents;

/// <summary>
/// Collection of different ContentField editors.
/// Feel free to extend this class by adding more Enum classes with ContentField editors.
/// </summary>
public static class ContentFieldEditorEnums
{
[Description("Editor options for HtmlFields.")]
public enum HtmlFieldEditors
{
Monaco,
Multiline,
Trumbowyg,
Wysiwyg,
}

[Description("Editor options for MarkdownFields. Wysiwyg editor can be used for MarkdownBodyParts as well.")]
public enum MarkdownFieldEditors
{
TextArea,
Wysiwyg,
}

[Description("Editor options for TaxonomyFields.")]
public enum TaxonomyFieldEditors
{
Tags,
}

[Description("Editor options for TextFields.")]
public enum TextFieldEditors
{
CodeMirror,
Color,
Email,
IconPicker,
Monaco,
PredefinedList,
Tel,
TextArea,
Url,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public static class ContentPartDefinitionBuilderExtensions
public static ContentPartDefinitionBuilder<TPart> AsPart<TPart>(this ContentPartDefinitionBuilder builder)
where TPart : ContentPart =>
new(builder);

/// <summary>
/// Sets the editor for a ContentField using an <see cref="Enum"/> parameter.
/// </summary>
public static ContentPartFieldDefinitionBuilder WithEditor(this ContentPartFieldDefinitionBuilder builder, Enum editor) =>
builder.MergeSettings<ContentPartFieldSettings>(x => x.Editor = editor.ToString());
}

public class ContentPartDefinitionBuilder<TPart>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using OrchardCore.ContentManagement.Metadata.Builders;
using System;

namespace OrchardCore.ContentManagement.Metadata.Settings;

public static class ContentTypePartDefinitionBuilderExtensions
{
/// <summary>
/// Sets the part's editor using an <see cref="Enum"/> parameter.
/// </summary>
public static ContentTypePartDefinitionBuilder WithEditor(this ContentTypePartDefinitionBuilder builder, Enum editor) =>
builder.MergeSettings<ContentTypePartSettings>(x => x.Editor = editor.ToString());
}
1 change: 1 addition & 0 deletions Lombiq.HelpfulLibraries.OrchardCore/Docs/Contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `ContentDefinitionManagerExtensions`: Adds extension methods to easily fetch settings objects from `ContentTypePartDefinition` objects.
- `ContentEnumerableExtensions`: Adds an extension for selecting parts in a collection of contents.
- `ContentExtensions`: Adds `ContentItem` manipulating extension methods to `IContent` objects, including the same ones that are available for the `ContentItem` objects (e.g. `As<T>()` or `Weld<T>()`).
- `ContentFieldEditorEnums`: Adds enums with the name of ContentField editors.
- `ContentHttpContextExtensions`: Adds `IContent` session related extension methods to `HttpContext`.
- `ContentOrchardHelperExtensions`: Extensions for managing content items better via `IOrchardHelper`.
- `ContentManagerExtensions`: Adds extension methods for retrieving, loading or creating content using the `IContentManager` interface.
Expand Down

0 comments on commit e45b4ae

Please sign in to comment.