-
-
Notifications
You must be signed in to change notification settings - Fork 20
Added features that allow consumers to customise View Location and runtime stylesheet loading #116
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
base: v3/dev
Are you sure you want to change the base?
Conversation
Hey @BenWhite27! I haven't forgotten about this, hoping to get on to it very soon. In the meantime, please can you pull in the latest changes from |
Hey @rickbutterfield, No worries, been tied up lately as well. I probably should have created a branch, still very new to contributing... especially in library code. I'll do a rebase locally in the next few days and update the fork asap. |
Updated nullability for the method and all references.
…tunities for 3rd party customisation. Set those methods as protected virtual to allow customisation.
Updated BlockPreviewApiController to include a new IBlockPreviewRequestEnricher field and modified the constructor to initialize it. Introduced IBlockPreviewRequestEnricher interface and a NoopBlockPreviewRequestEnricher.
…15+ compatible implementation instead.
…ws to render the correct themed partial view.
Afternoon @rickbutterfield, hope you're well. |
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.
Pull Request Overview
This PR adds features that allow consumers to customise View Location and runtime stylesheet loading for block previews. The implementation introduces a new service interface IBlockPreviewRequestEnricher
that enables enrichment of the HTTP context during block preview rendering, and modifies the BlockPreviewService
to allow extensibility around view resolution and stylesheet path retrieval. The changes enable theme-specific views and stylesheets to be displayed in the back office based on content properties.
- Added
IBlockPreviewRequestEnricher
service to allow HTTP context enrichment during block preview - Modified
BlockPreviewService
to support customizable view location and stylesheet paths through newBlockPreviewContext
- Updated the Backoffice UI to obtain stylesheets via API calls instead of static configuration
Reviewed Changes
Copilot reviewed 45 out of 46 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
assets.js | Updated JavaScript bundle with new API endpoints for stylesheet retrieval |
NoopBlockPreviewRequestEnricher.cs | Default no-op implementation of the request enricher interface |
BlockPreviewService.cs | Enhanced service with extensibility points for view resolution and stylesheet paths |
BlockPreviewContext.cs | New context class to pass block preview data between methods |
IBlockPreviewService.cs | Updated interface with new stylesheet path method |
IBlockPreviewRequestEnricher.cs | New interface for HTTP context enrichment |
BlockPreviewApiController.cs | Added API endpoints for retrieving stylesheets and integrated request enrichment |
BlockPreviewComposer.cs | Registered the default request enricher service |
Various UI files | Updated to use API calls for stylesheet retrieval instead of settings |
Example CMS files | Example implementation showing theme-based view resolution and styling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
ViewDataDictionary viewData = CreateViewData(blockInstance, previewContext); | ||
previewContext.ViewData = viewData; | ||
return await GetMarkup(previewContext); |
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.
The error message "Insufficient data for block preview" doesn't provide enough context about which specific data is missing. Consider enhancing the error message to specify exactly what data is required.
Copilot uses AI. Check for mistakes.
{ | ||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) | ||
{ | ||
Model = typedBlockInstance | ||
}; | ||
|
||
if (blockType == BlockType.BlockGrid && matchingBlockConfig != null && matchingBlockConfig.Areas.Any()) | ||
if (context.BlockType == BlockType.BlockGrid && context.BlockGridBlockConfig != null && context.BlockGridBlockConfig.Areas.Length != 0) |
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.
[nitpick] Complex conditional statement with multiple null checks. Consider extracting this logic into a helper method like 'HasBlockGridAreas(context)' for better readability.
if (context.BlockType == BlockType.BlockGrid && context.BlockGridBlockConfig != null && context.BlockGridBlockConfig.Areas.Length != 0) | |
if (HasBlockGridAreas(context)) |
Copilot uses AI. Check for mistakes.
Added
IBlockPreviewRequestEnricher
service that allows enrichment of the http context for runtime view and stylesheet location.Modified
BlockPreviewService
to allow extensibility aroundCreateViewData
andGetViewResult
. Making use of a newBlockPreviewContext
class to pass around the data needed to make decisions in custom logic. Also addedBlockPreviewService.GetStylesheetPath
to allow customisation of the stylesheet that is delivered at runtime.Updated the Backoffice UI code to obtain the stylesheet via API call.
Also added some example implementations to the CMS project.
This is all in relation to #115 with the goal of allowing a package consumer to display theme specific views in the back office. In theory the theme could be specified as a property in the content node hierarchy or based on the domain configured on the root content node.