Problem/Motivation

Given you have these themes:

  • base_theme
  • sub_theme

A sub-theme does not correctly inherit its base theme's libraries-override defined in base_theme.info.yml. If the default theme is base_theme, it works, but if you set sub_theme to default, the original asset will be rendered.

The only possible workaround I found, is to redefine (i.e. copy and paste) the overrides in the subtheme as well, but as the base assets and overrides can change later, this will cause your subtheme definitions to break.

I tested with overriding system/base assets, as base_theme by default inherits Stable. Tried to test with Bartik set to base theme in base_theme.info.yml, but it did not even work when base_theme was set to default theme. (This might be another issue)

The documentation does not mention this: https://www.drupal.org/docs/8/theming-drupal-8/creating-a-drupal-8-sub-t...

Here's my code:

base_theme.info.yml:

type: theme
name: Base theme
core: 8.x

libraries-override:
  system/base:
    css:
      component:
        /core/themes/stable/css/system/components/ajax-progress.module.css: css/ajax-progress.overridden.css

sub_theme.info.yml:

type: theme
name: Sub theme
core: 8.x
base theme: base_theme

Base theme set to default
Base theme correctly overrides
Sub theme set to default
Sub theme does NOT inherit base theme's override

Proposed resolution

The default theme should inherit everything defined in all of its parent themes, by common sense. This includes libraries-override too. Imagine having multiple projects (A, B, C) using the same base theme ("theme_root") which overrides a lot of system libraries, and you need only some minor theme tweaking in each project ("theme_a", "theme_b", etc...)

By the way, libraries-extend seems to work as expected.

Remaining tasks

  • Further testing with base theme: false, Stark, Classy, Bartik.
  • Fix inheriting library overrides.
CommentFileSizeAuthor
sub2.png134.84 KBgpap
sub1.png7.93 KBgpap
base2.png152.25 KBgpap
base1.png8.07 KBgpap
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gpap created an issue. See original summary.

gpap’s picture

Issue summary: View changes
gpap’s picture

Uploaded base_theme and sub_theme to GitHub for easier testing:

https://github.com/gergelypap/drupal-issue-2832430

gpap’s picture

Status: Active » Closed (works as designed)

Well, looks like it works, but I messed up the override paths. For those who find this issue by falling into the same trap, the correct usage of libraries-override is this:

libraries-override:
  MODULE_NAME/LIBRARY_NAME:
    css:
      theme:
        ORIGINAL_PATH: OVERRIDDEN_PATH
    js:
      ORIGINAL_PATH: OVERRIDDEN_PATH

ORIGINAL_PATH: This the same path that MODULE_NAME.libraries.yml lists under LIBRARY_NAME.

For example:

system.libraries.yml

base:
  version: VERSION
  css:
    # Adjust the weights to load these early.
    component:
      css/components/ajax-progress.module.css: { weight: -10 }
      css/components/align.module.css: { weight: -10 }
      # ...

my_base_theme.info.yml

libraries-override:
   system/base:
    css:
      component:
        css/components/ajax-progress.module.css: css/components/ajax-progress.css
        css/components/align.module.css: false

@todo - Update documentation in https://www.drupal.org/node/2216195#override-extend

a.milkovsky’s picture

Status: Closed (works as designed) » Needs work

@gpap thank you, that you shared your research results.

I have tried this:

ORIGINAL_PATH: This the same path that MODULE_NAME.libraries.yml lists under LIBRARY_NAME.

  1. Use the same path in the base theme as in the module
  2. Enable sub theme
  3. See that overrides are inherited
  4. Switch to the base theme
  5. See that overrides do not work

Expected: libraries override should work both in the base-theme and in the sub-theme.

FYI I am now trying to extend the https://www.drupal.org/project/thunder_admin theme.

a.milkovsky’s picture

Version: 8.3.x-dev » 8.4.x-dev

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

volkerk’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cedewey’s picture

Status: Needs work » Closed (duplicate)

Marking this closed and a duplicate of https://www.drupal.org/project/drupal/issues/2856499

a.milkovsky’s picture

But this issue is older...