Motivation
For previewing custom elements from within XB-previews, we need a way to generate that preview.
Proposed resolution
Provide a preview mechanism that supports multiple ways of handling previews. Lupus Decoupled needs one for Nuxt while allowing to add one for Next also. So we need some sort of provider/plugin mechanism.
Usually the same plugin/provider would be used for the whole site, but there might be use-cases to switch it based upon request, e.g. consider domain module / multi-site support.
While it makes sense to ship provides with custom elements module, the module lacks the knowledge/infrastructure to know where the frontend is running. So we could ship with the plugins and let Lupus Decouple expose UI and configuration to select and apply the suiting plugin.
For (the probably uncommon) usage of custom elements without Lupus Decoupled, we could add a dedicated module providing UI / config for that also, or leave it up the site-maintainer to add a glue module doing so.
Issue fork custom_elements-3542938
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- slots
compare
- 3542938-api
changes, plain diff MR !134
- 3542938-add-api-to
compare
Comments
Comment #2
fagoComment #5
fagoSo the preview-provider usually would happen automatically per-request, however there are use-cases where we want to select them:
1) Lupus Decoupled wants to add UI to allow the site-builder to choose from the list of given preview-providers, then apply them to the request.
2) Custom Elements might want to expose a UI during ce-entitity-display configuration that allows multiple preview-providers (e.g. Markup, Nuxt, ..). But that's in the end just two: the markup preview + what is the default for the request.
So it seems, all what is necessary for 2), is the service for preview providers + the way the resolve the right preview provider by request. We just make sure that preview-provider plugins implement PluginInspectionInterface - such that custom elements has the metadata about the resolved provider.
for 1), Lupus Decoupled wants to configure its own preview-provider-service based upon the configured plugin, so it can be resolved.
Comment #6
fagook, finally I've got something which I think is ready to go. It lays the ground-work, such that we can add individual preview-providers in separate issues now. For now, this will be #3548197: Add a Nuxt preview-provider using the nuxt-component-preview module with hopefully some next.js preview-provider following soon.
The architecture with both tagged-services and plugins might seems a bit overwhelming, but in the end we need both. I tried documenting it nice in code/interface to clarify what is the purpose of each.
Comment #7
useernamee commentedThat was my thought as well. I did not find a place where the need for both is explained.
Comment #8
fagoI commented at the MR. The docs are at https://git.drupalcode.org/project/custom_elements/-/blob/6dd32efafbc7ad... - does that explain it to you?
Additional background can be found at comment #5. I wrapped my head around it, but could not find a simpler way to achieve it. It might be more logical if lupus-decoupled would provide the plugin-manager, but then I think it's useful to have them in custom_elements module, so it could be used easily by any kind of decoupled-setup with having to use lupus-decoupled. One would have to provide necessary glue to provide the base-url, but that could even be done in a custom services.yml in a project.
Comment #9
useernamee commentedPassed technical review, but there are still phpcs and phpstan failures.
Internal discussion:
Comment #11
fagoThanks, moving on then!
The phpstan issues are already resolved in the next issue, so let'S get it addressed as part of it then.