Overview
You've heard of site templates. We're starting to build the first real-world one over in #3526844: [meta] Implement the first real-world site template and its children.
Site templates are, first and foremost, maximalist recipes. They have limited composability, and are focused on shipping a set of default content and a coherent look n' feel. That means they will lean heavily on Experience Builder, and need to be sure that the components they use (especially in their default content) are available during the process of applying the recipe.
After fighting through bugs with @larowlan in #3530376: Set up scaffolding for the SaaS Product site template, I found that all we really need XB to do is refresh the available components at certain critical points of the recipe application process. The good news is, the recipe system dispatches events at those points, so XB should just subscribe to them. Specifically:
- The default content system's
PreImportEventshould trigger a component refresh. This will allow the recipe to include default content which uses XB (landing pages, for example). - XB should also do a component refresh when the recipe system dispatches its
RecipeAppliedEvent. This is to cover recipes which don't ship any default content -- we still want any new components to be available to XB without the user needing to do a cache clear (which, given the target audience for site templates, they may not know how to do).
Proposed resolution
Add an event subscriber which calls getDefinitions() on the component and block plugin managers whenever those two events occur.
The test coverage should confirm that if you apply a recipe -- with or without default content that uses XB -- the components in any of the recipe's dependencies are generated.
User interface changes
This change will not touch the UI.
Issue fork experience_builder-3530791
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:
Comments
Comment #3
phenaproximaI've added some test coverage against an existing test-only recipe in XB, and it proves that if you disable either event subscriber, recipe import fails.
Comment #4
mglamanLGTM!
Comment #6
wim leersComponentSources we have today (block + sdc).See the MR comment + #3526045-7: Settle on final name for `ComponentSource` plugins (`ComponentType`?) + expand their scope (discovery, maybe more?) for how this could be achieved.
Comment #7
phenaproximaRetrieving definitions will regenerate all the component entities if needed (as you know), but you're right that this is setting up a bug if the cache is not empty. So I added an explicit cache clear.
I changed the subscriber to a service collector for
CachedDiscoveryInterface. That still ties it to plugins...for now. But using a service collector gives us some more leeway later, if we add a new interface for component discovery. That will make it easier to refactor. I didn't do it as you suggested in https://www.drupal.org/comment/16120596#comment-16120596 because that would make the dependency injection trickier/impossible. Besides, service collection is a well-used pattern in core and seems like a good fit here.Looks like the only one outstanding is in component-operations.cy.js, with the same failing assertion that seems to inexplicably haunt every goddamned MR I submit to Experience Builder. :) I don't see how the changes here could be affecting that, since the recipe event subscriber only does anything if a recipe is applied. I'm not really sure how to approach fixing it, since I'm not sure the cause of it was ever discovered the previous times I encountered it.
As for the Playwright failure, I will eat my socks if this MR is related to it, and you'll agree with me when you see why the job is failing: https://git.drupalcode.org/issue/experience_builder-3530791/-/jobs/56231...
Comment #8
wim leersThat last commit is 🤩👏
Comment #10
wim leersComment #11
justafishThis caused Playwright to fail, I've reverted some of it in https://www.drupal.org/project/experience_builder/issues/3532130
Comment #12
wim leers@justafish is there more to be done here, or can we close this again? 🤞
(Not working today but bringing order to persona life after XB craziness — including closing >100 tabs on my tablet 🤣🥳)
Comment #13
wim leersThis status probably makes more sense?
Comment #14
justafishNothing more to be done here, it was fixed in https://www.drupal.org/project/experience_builder/issues/3532268
Comment #15
wim leersThanks! That’s what I thought/hoped — but apparently failed to link 😅