You've built sites with Drupal and know that with a few dozen modules (and a ton of configuring), you can do nearly everything in modern Drupal.
But what do you do when there's not a module for that? When the modules that exist don't meet your needs, and cannot be made to by contributing changes?
You make your own.
This blog post accompanies the New England Drupal Camp session and helps you take that step. All you need to do is write two text files. The first file tells Drupal about the module; it is not code so much as information about your code. The second file can have as little as three lines of code in it. Making a module is something that anyone can do. Every person developing a module is still learning.
Slides source code: https://gitlab.com/agaric/presentations/when-not-a-module-for-that
(Site with slides coming.)
This is about the simplest module you can make, and—unlike the popular implications of its name—is not growing by adding bits and pieces of other modules as we build a monstrosity (that is what we will do later, as exhuming and incorporating adaptations of other modules' code is our main technique for making new modules).
Frankenstein (example) | Drupal.org
Sharing your module out into the world
Put your module on Drupal.org: drupal.org/node/add/project-module
(I honestly do not know where they hide that link, but remember on any Drupal site you can go to /node/add
and see what content you have access to create, and that includes creating projects on Drupal.org!)
It will start its life as a "sandbox" module by default.
Tip: Do not try to choose a part of core under "Ecosystem", and always check that the node ID it references is really one you want— there are a lot of projects with similar or even the same name.
Do not get overwhelmed; you can come back and edit this page later.
Press Save.
Then press the Version control tab to go to a page with Git instructions tailored to your module.
If you have already started your module and made commits in a repository dedicated to only your module, make certain your commits are on a branch named 1.0.x
(the instruction included there git checkout -b 1.0.x
will be enough to do that) and then follow only the git remote add
and git push
steps.
Double-checked to make certain the "Frankenstein" example module would not be better an example of when already "There's a module for that" and discovered the sad backstory— it exists in Drupal 7, people wanted it ported to modern Drupal, someone did port it to modern Drupal, but in a private GitHub repository and module maintainers did not take action and now that repo is gone.
Contributing to an existing module
(To do: Make into its own post.)
I apologize, on behalf of all of Drupal, that this is harder than it ought to be.
First, create an issue (if there is not one already) stating the needed feature or bug fix.
Before you start modifying the module's code, go into your project's composer.json
and edit the version of the module you are using and want to contribute to and make it the dev version.
If you have gotten the module as ^3.0@RC
for example, change that to ^3.0.x-dev@dev
.
Run composer update
.
Now, so long as you do not have a restriction in your composer.json
, composer will get the git repository of that module for you and put it in the usual place for contributed modules, such as web/modules/contrib
.
follow the instructions in the issue to
Now you need to make a merge request.
Comments
Add new comment