With #474684: Allow themes to declare dependencies on modules themes can now specify dependencies on modules, which means more fundamentally that they can safely use functionality provided by modules. For example a theme could depend on the jquery_update module.
To declare a dependency in your theme you need to add it to the .info.yml
file:
name: test theme depending on nonexisting module
type: theme
core_version_requirement: ^8 || ^9
dependencies:
- my_custom_module:my_custom_module
- drupal:test_module_non_existing
You should also add the module as a dependency in composer.json, so that it is correctly installed via composer when the theme is installed: https://www.drupal.org/docs/8/creating-custom-modules/add-a-composerjson...
Existing themes that add a new module dependency will fail to update correctly on existing sites unless they install the module first, so when relying on this feature in an existing contributed theme, please communicate clearly to users that there is a new dependency - via the release notes, incrementing the major version number, or similar measures.
Any admin themes that customise the system-themes-page.html.twig
template need to update their template overrides for changed markup.
Comments
Does not enable modules
I tested it and I believe, the dependencies will not enable the module. I checked into the code and it does not enable the module. This does not work the same way as for a module.
Reason - unknown.
Vaibhav Jain
Does not work
This new feature does not work => #3176625: Install from existing config with a theme that declares module dependencies fails
I believe the correct format
I believe the correct format as of 9.4 is as follows:
I'm convinced you're right,
I'm convinced you're right, @thtas. You pasted yml from a test theme in the system module, so that has to be the right syntax.
I have updated the change record.