Motivation
It would be neat if Component Library could override templates without the use of additional modules.
Proposed resolution
The pluggable patterns patch introduced the ability to override theme components without the use of additional modules like ui_patterns. This merge request uses that patch as a starting point to override templates from within Component Library. In an effort to not mess up the Pattern + Variant entities that Component Library uses with ui_patterns, how about we add a Component Override entity and plugins that focus on just overriding things?
User interface changes
- Adds a Component Override section to the theme settings page.
Data model changes
- Adds a Component Override entity.
Testing
- On a fresh install, add an Article and then enable component_library.
- Navigate Appearance > Settings (on the active theme) and click the "Add component override" button on the theme settings page.
- Fill out the following:
-
- Label: Article
- Theme: Bartik
- Plugin: Content
- Bundle: Article
- View mode: Default
- Override: node__article
- Tweak the template.
- Click "Save", and reload the article.
Please see the demo.

Remaining tasks
- ¯\_(ツ)_/¯
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2022-01-28_16-39.png | 158.62 KB | heddn |
| #7 | component-override-variables.gif | 10.2 MB | tim bozeman |
| #7 | component-override-variables.mp4 | 37.33 MB | tim bozeman |
| #3 | component-override.gif | 2.62 MB | tim bozeman |
| #3 | component-override-ui.png | 184.38 KB | tim bozeman |
Issue fork component_library-3259011
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
Comment #3
tim bozeman commentedComment #4
tim bozeman commentedComment #6
tim bozeman commentedComment #7
tim bozeman commentedThe pluggable patterns patch overrode the theme registry functions for preprocessing variables and rendering the template. Lets try a twig loader and use events for preparing variables and theme suggestions.
Comment #9
heddnAfter loading admin/appearance/settings/{{theme}}/component-library/override/add
I got:
Comment #10
tim bozeman commentedThanks for the git fu @heddn!
@s_leu I added this tweak that limits the extension listing to installed extensions to address #9. Will that work?
Comment #11
s_leu commentedRegarding #10, thanks @Tim Bozeman, that change certainly makes sense.
Comment #12
tim bozeman commentedThis is probably a good stopping point for the foundational part. Whatcha think?
Comment #14
heddnThanks for your collaboration on this work.