ddev-drupal-dev cheat sheet¶
Quick reference for the most common commands. See the documentation for details.
Contrib modules¶
ddev add-module token # clone + require token
ddev add-module token 2.0.x # specific branch
ddev add-module --https token # clone over HTTPS (no push access)
ddev switch token 2.0.x # switch branch + update constraint
ddev switch --pull token 2.0.x # also fast-forward the branch first
ddev update-module token # re-sync constraint after switching branches yourself
ddev remove-module token # remove require, repo entry, and clone
Modules land in modules/contrib/<name> as git checkouts.
Core¶
ddev switch core 11.x # switch core branch + composer update
ddev switch --pull core 11.x # also fast-forward 11.x first
Merge requests¶
ddev mr core 16853 # a merge request number
ddev mr core 3563677 # an issue number, resolved to its merge request
ddev mr token 136 # a contrib module's merge request
ddev mr https://git.drupalcode.org/project/drupal/-/merge_requests/16853
ddev mr https://www.drupal.org/project/drupal/issues/3563677
Adds the issue fork as a remote tracking only the merge request branch, checks
it out and re-solves the overlay. The branch tracks the fork, so a plain
git push updates the merge request. --https for a remote you cannot push to.
Composer overlay¶
ddev composer install # install everything (core + overlay)
ddev composer require drupal/pathauto # add a package without cloning
ddev composer require --dev phpstan/phpstan
ddev composer update # re-solve overlay
The overlay lives in composer.local.json; core's composer.json and composer.lock are never touched.
Tests¶
ddev phpunit core/modules/node # project database (default)
ddev phpunit --db=sqlite core/modules/node # SQLite
ddev phpunit --db=pgsql core/modules/node # PostgreSQL (needs ddev-postgres)
ddev phpunit --db=mariadb core/modules/node # MariaDB (see .ddev/drupal-dev/docker-compose.mariadb.yaml.example)
ddev phpunit modules/contrib/token # contrib module tests
cd modules/contrib/token && ddev phpunit tests/src/Kernel # paths relative to where you are
Code quality¶
ddev phpstan core/modules/node # PHPStan on specific paths
ddev phpstan modules/contrib/token # a contrib project, with its own configuration
ddev phpcs core/modules/node # coding standard checks
ddev cspell core/modules/node/** # spell checking (globs)
Each command uses the configuration of the project being checked, and core's for
anything that has none. Run any of them without arguments to check the directory
you are in, or the whole codebase from the project root. ddev cspell needs
core's node dependencies:
ddev exec 'corepack enable && cd core && yarn install'.
Core's pre-commit script, on your changed files only:
ddev commit-code-check # working directory changes
ddev commit-code-check --cached # staged files only
ddev commit-code-check --branch 11.x # changes compared to a branch
Run tools from anywhere in the project¶
ddev phpunit, ddev phpcs, ddev phpstan and ddev cspell take paths relative to the directory you run them from. Run them from the Drupal project root with the module path, e.g. ddev phpcs modules/contrib/dashboard, or from inside the module, e.g. cd modules/contrib/dashboard && ddev phpcs src. Each tool uses the module's own configuration. Without one, a module with a .gitlab-ci.yml gets the default configuration contrib CI uses, and anything else gets core's.
Pin core's exact dependency versions¶
In composer.local.json:
Then ddev composer update once to regenerate the lock with pinning applied.
Host-side shell helpers¶
Add to ~/.bashrc or ~/.zshrc so bare composer, drush, php, phpunit, dr auto-delegate to DDEV:
If you use direnv: run direnv allow in the project root.