Problem/Motivation

drush bs-tc (BsLibCommands::themeCreate()) builds the child theme's .info.yml in BsLibCommands::generateFile() from the parent theme's info array. It removes libraries-extend and component-libraries, but it keeps the components key, which is where Components 3.x reads Twig namespaces:

components:
  namespaces:
    atoms:
      - components/_patterns/01-atoms
    molecules:
      - components/_patterns/02-molecules
    organisms:
      - components/_patterns/03-organisms

The paths are relative to the theme that declares them. The child theme does not get a components/ folder (copyThemeFiles() does not copy it), so every path points to a folder that does not exist. On every cache rebuild Components logs one warning per namespace from ComponentsRegistry::load():

The "@organisms" namespace contains a path, "themes/custom/design/components/_patterns/03-organisms", that is not a directory.

The copied key is not new: child themes created with bs-tc have carried it for a long time. It only shows up now because of the Components version. Components 8.x-2.x skips a namespace path that is not a directory without a message, so sites on 2.x have the same copied block and an empty log. Components 3.x logs the warning above, so the problem becomes visible when a site updates to Components 3.x.

The copied key is also not needed. ComponentsRegistry::findNamespaces() merges the namespaces of all base themes into the active theme, so templates in the parent's namespaces resolve in the child theme without the child declaring them.

Steps to reproduce

  1. Install the Components module (3.x) and a bs_base based theme whose .info.yml has components: namespaces: with relative paths (for example a theme with Pattern Lab folders under components/_patterns/).
  2. Run drush bs-tc <parent> mytheme "My theme" "My theme" and enable mytheme as the default theme.
  3. Run drush cr and open any page.
  4. The log has one "namespace contains a path ... that is not a directory" warning per namespace, for paths under themes/custom/mytheme/components/.

Proposed resolution

In BsLibCommands::generateFile(), remove the components key together with component-libraries:

// Remove libraries-extend and the Components module namespaces. The
// namespace paths are relative to the parent theme, and Components
// already gives a sub-theme the namespaces of its base themes.
unset($yaml_array['libraries-extend']);
unset($yaml_array['component-libraries']);
unset($yaml_array['components']);

A child theme that later adds its own components folder declares its own namespaces.

Remaining tasks

  • Patch.
  • Decide whether existing child themes need a bs_update hook that removes components paths that do not exist in the child theme, or only a note in the release notes.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork bs_lib-3628921

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

pivica created an issue. See original summary.

  • pivica committed 733d897b on 2.0.x
    fix: #3628921 bs-tc copies the parents components namespaces into the...
pivica’s picture

Status: Active » Fixed

Done.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.