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 PreImportEvent should 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.

Command icon 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

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review

I'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.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

LGTM!

wim leers’s picture

Component: Config management » Component sources
Status: Reviewed & tested by the community » Needs work
Related issues: +#3526045: Settle on final name for `ComponentSource` plugins (`ComponentType`?) + expand their scope (discovery, maybe more?)
  1. I don't yet understand why merely retrieving definitions is sufficient (and nor did @larowlan) — see MR comment for details. Can you articulate why? 🙏
  2. This must be generalized to not hardcode assumptions for the 2 plugin-powered ComponentSources 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.

phenaproxima’s picture

Status: Needs work » Needs review

I don't yet understand why merely retrieving definitions is sufficient (and nor did @larowlan) — see MR comment for details. Can you articulate why?

Retrieving 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.

This must be generalized to not hardcode assumptions for the 2 plugin-powered ComponentSources we have today (block + sdc).

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.

there's some CI fails we likely need to address

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...

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

That last commit is 🤩👏

wim leers’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #3520484: [META] Production-ready ComponentSource plugins
wim leers’s picture

Assigned: Unassigned » justafish

@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 🤣🥳)

wim leers’s picture

Status: Needs work » Patch (to be ported)

This status probably makes more sense?

justafish’s picture

Status: Patch (to be ported) » Fixed

Nothing more to be done here, it was fixed in https://www.drupal.org/project/experience_builder/issues/3532268

wim leers’s picture

Assigned: justafish » Unassigned

Thanks! That’s what I thought/hoped — but apparently failed to link 😅

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.