Skip to content
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

LMBQ-276: Improving WithEditor #230

Merged
merged 12 commits into from
Dec 30, 2023
MZole marked this conversation as resolved.
Show resolved Hide resolved
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