Score:0

How to create a configuration export such that it installs two modules, one of which has a dependency on the other?

cn flag

I've written a custom module that uses jwt.transcoder service from the jwt module. In turn, it provides another service:

$ cat mymodule.services.yml
services:
  mymodule.jwt:
    class: Drupal\mymodule\Services\Jwt
    arguments: [ '@jwt.transcoder', '@event_dispatcher' ]

Everything went smoothly during development. However, neither the jwt module, nor my new custom module, were installed on our site before I started developing this feature.

I added both modules with composer, and did a config export to enable them (and set up the cryptographic keys, etc). However, when I go to do a deployment, I get an error on the config import, which apparently is coming from a dependency on the jwt.transcoder service, which is not yet installed at this point.

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
                                                                                      
  The service "mymodule.jwt" has a dependency on a non-existent service "jwt.transcoder". 

With our deploy process, we can only deploy one codebase at a time-- meaning that, if I wanted to do a config import to get jwt installed first, and another config import with the enabling of my custom module, I would have to do a second deploy to do get that second config codebase up on the server.

Is there any way to get the config import to install jwt first, and then my custom module, in a single codebase, so this dependency is resolved?

sonfd avatar
in flag
Is "jwt" marked as a dependency of "mymodule" in mymodule.info.yml?
cn flag
@sonfd that was it! Thank you. Please put that in an answer and I will accept it : )
Score:3
in flag

You need to mark the jwt module as a dependency of mymodule in mymodule.info.yml, via the dependencies key.

dependencies: a list of other modules your module depends on. Dependencies on Drupal core or contrib modules should be namespaced in the format {project}:{module}, where {project} is the project name as it appears in the Drupal.org URL (e.g. drupal.org/project/views) and {module} is the module's machine name. Dependencies can also include version restrictions, for examplewebform:webform (>=8.x-5.x). Note that if your module has dependencies on other contributed modules or libraries, these should be declared in the module's composer.json file. If you have local custom modules that are dependent on each other you can use {module}:{module} (or {module}:{submodule} for sub-modules.)

Source: Let Drupal know about your module with an .info.yml file

For example, inside your mymodule.info.yml:

name: My Module
type: module
...
dependencies:
  - jwt:jwt
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.