How to install a Drupal.org sandbox module using Composer

What do you do if you want to use a Drupal.org sandbox project with Composer? You can’t just add it in your "require" section, as it won’t be available as a package name. Turns out you just have to define the repository in your composer.json like so:

Javascript

"repositories": {
  "drupal/image_field_caption": {
    "type": "package",
    "package": {
      "name": "drupal/image_field_caption",
      "type": "drupal-module",
      "version": "1.x-dev",
      "source": {
        "url": "https://git.drupalcode.org/sandbox/spoit-2806183.git",
        "type": "git",
        "reference": "8.x-1.x"
      }
    }
  }
},
"require": {
  // ...
  "drupal/hook_event_dispatcher": "^1.23",
  "drupal/image_field_caption": "1.x-dev",
  // ...
},
// ...

Tags: