Add a theme configurator so recipes can generate themes

Created on 16 May 2025, 7 days ago

Problem/Motivation

As I have been experimenting and trying to adapt recipes into my site creation flow, I would like to automate the process of generating a (starterkit) theme on a (new) site as part of applying a recipe. At the moment, generating a theme is a manual command.

This could be useful for agencies to improve getting started on a new site. As well, it would be useful for multi-tenant site builders (like Tumblr) where an end user gets a fully customizable theme to play around without extra commands.

A recipe could provide input in the case where there are multiple starterkit themes available or a contributed recipe may have a pre-configured starterkit theme that would generate a theme. This could also be used for pre-existing sites to apply a recipe during a redesign.

Steps to reproduce

  1. A user applies a recipe that configures custom theme
  2. A theme is generated in themes/custom/(theme name)
  3. A user can enable the theme if it is not enabled by the recipe

Proposed resolution

A recipe can define options to generate and then enable a custom theme.

Remaining tasks

- Find consensus on building out the proposed resolution.
- Code it.
- Test it.
- Document it.

User interface changes

Yes, to be determined (TBD)

Introduced terminology

Yes, TBD.

API changes

Maybe.

Data model changes

Yes, TBD.

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

recipe system

Created by

πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

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

Comments & Activities

  • Issue created by @mradcliffe
  • πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

    I think the YAML configuration would be something like this where a theme might want to make use of values provided by the InputConfigurator.

    input:
      theme_name:
        data_type: string
        constraints:
          NotBlank: []
        prompt:
          method: ask
       default:
         source: value
         value: 'my_theme'
    
    config:
    
    theme:
      -
        name: my_theme
        #name: '${theme_name}'
        description: 'A description of your theme.'
        enable: true
        starterkit: 'starterkit_theme'
        path: 'themes/custom'
    

    Much of theme generation is in GenerateTheme command, which may be better someplace else in core.

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Love this idea!

  • πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

    From @mglaman, potential things that may need to be done as part of this:

    • Core should expose a way to do batch API over CLI. Basically what Drush has for it as a proper API
    • Extract command to a service that uses batch, command basically runs that batch
    • Allows recipe runner to use that batch for the theme generation
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    I think this should be a series of issues, but going for a "big bang" fix just to prove its possible.

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    I started working on this and realized that it will cause a whole bunch of internal things needing to be exposed as public static methods and also cause us to lose some of the verbosity output when generating a command.

    There is also another issue if the spun out code uses TranslatableMarkup because it requires a container and the GenerateTheme command was made specifically to work without an installed Drupal site.

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    In an interim I wonder if we can just add `theme` as proposed and in \Drupal\Core\Recipe\RecipeRunner::toBatchOperationsRecipe we had a matching method which runs the command over CLI. The biggest problem would be timeouts since we cannot batch it into smaller operations. Is that acceptable?

Production build 0.71.5 2024