-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-680: Add default handler, example and docs for the Content Sets feature in Lombiq.HelpfulExtensions
- Loading branch information
Showing
21 changed files
with
838 additions
and
75 deletions.
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
61 changes: 61 additions & 0 deletions
61
...fulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.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,61 @@ | ||
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; | ||
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; | ||
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; | ||
using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; | ||
using Lombiq.HelpfulLibraries.OrchardCore.Contents; | ||
using Microsoft.Extensions.Localization; | ||
using Newtonsoft.Json.Linq; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Display.ContentDisplay; | ||
using OrchardCore.ContentManagement.Display.Models; | ||
using OrchardCore.ContentManagement.Metadata; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
using OrchardCore.DisplayManagement.Views; | ||
using System.Collections.Generic; | ||
|
||
namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; | ||
|
||
public class ContentSetContentPickerFieldDisplayDriver : ContentFieldDisplayDriver<ContentSetContentPickerField> | ||
{ | ||
private readonly IContentDefinitionManager _contentDefinitionManager; | ||
private readonly IContentSetManager _contentSetManager; | ||
private readonly IEnumerable<IContentSetEventHandler> _contentSetEventHandlers; | ||
private readonly IStringLocalizer<ContentSetPart> T; | ||
|
||
public ContentSetContentPickerFieldDisplayDriver( | ||
IContentDefinitionManager contentDefinitionManager, | ||
IContentSetManager contentSetManager, | ||
IEnumerable<IContentSetEventHandler> contentSetEventHandlers, | ||
IStringLocalizer<ContentSetPart> stringLocalizer) | ||
{ | ||
_contentDefinitionManager = contentDefinitionManager; | ||
_contentSetManager = contentSetManager; | ||
_contentSetEventHandlers = contentSetEventHandlers; | ||
T = stringLocalizer; | ||
} | ||
|
||
public override IDisplayResult Display( | ||
ContentSetContentPickerField field, | ||
BuildFieldDisplayContext fieldDisplayContext) | ||
{ | ||
var name = fieldDisplayContext.PartFieldDefinition.Name; | ||
if (field.ContentItem.Get<ContentSetPart>(name) is not { } part) return null; | ||
|
||
return Initialize<ContentSetContentPickerFieldViewModel>(GetDisplayShapeType(fieldDisplayContext), model => | ||
{ | ||
model.PartFieldDefinition = fieldDisplayContext.PartFieldDefinition; | ||
return model.InitializeAsync( | ||
_contentSetManager, | ||
_contentSetEventHandlers, | ||
T, | ||
part, | ||
new ContentTypePartDefinition( | ||
name, | ||
_contentDefinitionManager.GetPartDefinition(nameof(ContentSetPart)), | ||
new JObject()), | ||
isNew: false); | ||
}) | ||
.Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content) | ||
.Location(CommonContentDisplayTypes.Summary, CommonLocationNames.Content); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.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,12 @@ | ||
using OrchardCore.ContentManagement; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; | ||
|
||
[SuppressMessage( | ||
"Minor Code Smell", | ||
"S2094:Classes should not be empty", | ||
Justification = "Only data we need is the field name.")] | ||
public class ContentSetContentPickerField : ContentField | ||
{ | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...pfulExtensions/Extensions/ContentSets/ViewModels/ContentSetContentPickerFieldViewModel.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,8 @@ | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; | ||
|
||
public class ContentSetContentPickerFieldViewModel : ContentSetPartViewModel | ||
{ | ||
public ContentPartFieldDefinition PartFieldDefinition { get; set; } | ||
} |
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
15 changes: 15 additions & 0 deletions
15
....HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.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,15 @@ | ||
using Lombiq.HelpfulLibraries.OrchardCore.Workflow; | ||
using Microsoft.Extensions.Localization; | ||
|
||
namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; | ||
|
||
public class ContentSetCreatingEvent : SimpleEventActivityBase | ||
{ | ||
public override LocalizedString DisplayText => T["Creating Content Set"]; | ||
public override LocalizedString Category => T["Content Sets"]; | ||
|
||
public ContentSetCreatingEvent(IStringLocalizer<ContentSetCreatingEvent> stringLocalizer) | ||
: base(stringLocalizer) | ||
{ | ||
} | ||
} |
Oops, something went wrong.