Setting up a local development environment with DDEV to contribute to Drupal core

Contributing to Drupal core is a little different to contributing to a contrib module. This blog post was written during my Drupal core contribution time, sponsored by Code Enigma.

Code Enigma Logo

When contributing to Drupal contrib, it's quite easy to git clone the module you want to work on into your codebase, do your work, and push it back up for the community to validate.

The set up when contributing to Drupal core is a little bit more complex. I haven't had the space to contribute to Drupal core as much as I'd like recently, but am now in a position to do so again, thanks to very generous sponsorship from Code Enigma.

When I started setting up my environment this morning, I ran into a few issues. Actually, really just one issue, but I couldn't solve it, so I came up with what is either:

  1. A workaround, or 
  2. A better way!

I'm quite new to DDEV, but so far I'm lovin' it! I followed the Drupal.org docs for setting up DDEV for core contributions 

  1. Install DDEV
  2. Clone core
  3. Run ddev config --project-type drupal10 --docroot .
  4. Run ddev start
  5. Run ddev composer install
  6. Run ddev composer require drush/drush

However, this resulted in the following error when ever I tried to install Drush, which meant I couldn't get to the final step ddev drush site:install y.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires drupal/core 1.0.0 (exact version match: 1.0.0 or 1.0.0.0), found drupal/core[dev-main] but it does not match the constraint.
  Problem 2
    - Root composer.json requires drupal/core-project-message 1.0.0 (exact version match: 1.0.0 or 1.0.0.0), found drupal/core-project-message[dev-main] but it does not match the constraint.
  Problem 3
    - Root composer.json requires drupal/core-vendor-hardening 1.0.0 (exact version match: 1.0.0 or 1.0.0.0), found drupal/core-vendor-hardening[dev-main] but it does not match the constraint.

I'm not exactly sure why, but Drush was not going to be installed. 

I did some Googling, I did some changing this and changing that, but all to no avail. Then I remembered the oh sooo brilliant composer flag --prefer-source

So I started over again, and here's my "A Better Way".

  1. Install Drupal via DDEV as you normally would, following the "Drupal Quickstart Guide"
  2. Once everything is installed, reinstall all your packages that are within the drupal/* namespace but use the git versions of them instead, using this command ddev composer reinstall --prefer-source "drupal/*"
  3. cd to your /web/core/ directory and git checkout 11.x (or whatever branch you want)
  4. cd back to your DDEV root and install your site via ddev drush si -y.

I'd be very happy to hear from others how they set up their environments for Drupal core contribution. 

Filed Under:

  1. Drupal Planet
  2. Drupal
  3. Open Source
  4. DDEV