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
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.
Comment | File | Size | Author |
---|
Comments
Comment #2
gpap CreditAttribution: gpap at Brainsum commentedComment #3
gpap CreditAttribution: gpap at Brainsum for Tieto commentedUploaded base_theme and sub_theme to GitHub for easier testing:
https://github.com/gergelypap/drupal-issue-2832430
Comment #4
gpap CreditAttribution: gpap at Brainsum for Tieto commentedWell, 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:ORIGINAL_PATH: This the same path that MODULE_NAME.libraries.yml lists under LIBRARY_NAME.
For example:
system.libraries.yml
my_base_theme.info.yml
@todo - Update documentation in https://www.drupal.org/node/2216195#override-extend
Comment #5
a.milkovsky@gpap thank you, that you shared your research results.
I have tried this:
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.
Comment #6
a.milkovskyComment #8
volkerk CreditAttribution: volkerk commentedComment #10
cedeweyMarking this closed and a duplicate of https://www.drupal.org/project/drupal/issues/2856499
Comment #11
a.milkovskyBut this issue is older...