Set up scaffolding for the B2B SaaS site template

Created on 16 June 2025, 7 days ago

Problem/Motivation

In order to build our first real-world site template (for a fake business-to-business SaaS product), we'll need a new recipe in which to develop it. Let's set that up in our internal development dependencies.

πŸ“Œ Task
Status

Active

Component

General

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @phenaproxima
  • @phenaproxima opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    @phenaproxima can we update it from b2b_saas, to saas_product?

  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • First commit to issue fork.
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Poked at this after chatting with Adam

    There were two issues:

    1) missing component versions - I fixed this and pushed
    2) the recipe runner installs modules before themes

    I put a debugger on the drupal_flush_all_caches call in experience_builder_install and stepped into \Drupal\experience_builder\Plugin\ComponentPluginManager::setCachedDefinitions

    At that point the mercury theme doesn't exist - so no component config entities get created for the SDC

    But when we get to the theme install step, on 11.2 that yields a cache clear of the plugin definitions _but_ we're in a ::isSyncing TRUE state, and hence the logic in \Drupal\experience_builder\Plugin\ComponentPluginManager::setCachedDefinitions is skipped

    I think that means we might need to ship default component config entities, which is the opposite of what I told Adam in a call earlier.

    But then I tried adding them, and the issue is that the plugins don't exist at that point, because the clearing of the cache in the theme installer doesn't do discovery, it just clears the cache.

    So I then added this to experience_builder.install

    function experience_builder_themes_install(): void {
      \Drupal::service(ComponentPluginManager::class)->getDefinitions();
    }
    

    But that didn't seem to help either.

    I've pushed up the config, hopefully this helps Adam pinpoint where the issue lies.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    It might have just been the hook being wrong. It's hook_themes_installed, not hook_themes_install.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Discussed with Adam and we agreed getting XB to listen to default content pre import event and making sure it has generated components feels like a good approach to make sure this race condition doesn't happen

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Discussed this with @larowlan a bit more and I think we have our solution.

    First of all, having the recipe ship the Component config entities is, we agreed, the worst of all possible worlds. It's basically having to maintain the components in two places (Mercury, and the recipe). The coupling is a nightmare. Mediacurrent also feels that this is very much the wrong path.

    So the fix probably lies in Experience Builder supporting recipes in some way. Lee suggested a config action that creates the components. That would work, but would be awkward because config actions generally need to target some existing config object. So I had an idea that we both liked better - how about if Experience Builder subscribes to the DefaultContent system's PreImportEvent, and unconditionally creates the components before importing content? That should vault us past this hurdle.

    I think we may still want to have a config action as well, to ensure that specific components are created when needed, but that can be a separate feature request in XB and would not be a blocker to building this site template.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    XB follow-ups needed here, which will allow us to remove nearly all the patches I'm adding here:

    • Fix XB's broken service decoration (already exists)
    • Subscribe to recipe events to ensure that you have all component entities properly generated for you once the recipe is applied, and before content is imported
    • Call processDefaultValue() on field items when generating component entities, since that is necessary to actually be conformant with field schema
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Whew. That was quite a slog, but with much help, we made it. Obviously the template is not usable in the wild, but at least we've got something we can iterate on! Merged into 2.x.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
Production build 0.71.5 2024