How to use a version of a module from a Drupal issue fork in Composer

2 years ago 53

How to use a version of a module from a Drupal issue fork in Composer Jay Beaton Friday, 16 Jun 2023 @ 5:24pm I've had this question several times and found it hard to find the answer. So, if only for my own reference, here it is! If you need to use the code from a Drupal issue fork (rather than a patch) in Composer, you need to... 1. Get the URL of the issue fork. You can find this on the issue page itself. For example, on this issue for Entity Group Field, you can get it here next to where it says "Issue fork": Copy that URL. In this case, it's https://git.drupalcode.org/issue/entitygroupfield-3306512 2. Find the particular commit in that issue fork that you want to use. If you look under "Commits" on the GitLab page, you can find the commit hash of the one you want. In this case, we'll use this commit: https://git.drupalcode.org/issue/entitygroupfield-3306512/-/commit/2fd46a02ae6ceca69ab81083463c7ba28434a75e Its hash is "2fd46a02ae6ceca69ab81083463c7ba28434a75e". Note that using a specific hash makes your site a bit more secure. If you just used the HEAD of the branch, you could end up using whatever the last commit pushed to this issue branch was. That could break your site (or worse!). 3. Add a new "repositories" section to your composer.json file. This should go above the existing entries in the repositories section. Note that I'm using the name of the Drupal package (drupal/entitygroupfield), the URL of the issue fork and the hash of the commit (from above). The "version" should match that of the package you're using. diff --git a/composer.json b/composer.json index 9a268b889..abeeb4aa4 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,19 @@ "chat": "https://www.drupal.org/node/314178" }, "repositories": { + "entitygroupfield": { + "type": "package", + "package": { + "name": "drupal/entitygroupfield", + "version": "1.0.x-dev", + "type": "drupal-module", + "source": { + "url": "https://git.drupalcode.org/issue/entitygroupfield-3306512.git", + "type": "git", + "reference": "2fd46a02ae6ceca69ab81083463c7ba28434a75e" + } + } + }, "lenient": { "type": "composer", "url": "https://packages.drupal.org/lenient" 4. Include the module using Composer. Now, you can "run "composer require" to add the module code from the issue fork: composer require drupal/entitygroupfield:1.0.x-dev Make sure to specify the version you set above.   That's does it! Now, you've got the code with the changes you need. You will need to update that commit has and run "composer require" again if you want to change the particular commit you're using.   Drupal composer


View Entire Post

Read Entire Article