Steps to Create Patch in Drupal.

Drupal Contribution

  • Create a patch
  • Review a patch

Details

Welcome to the Drupal community’s Contributor Guide! In this section of the Drupal.org web site, you will find information to help you figure out how you can bring your unique skills and perspectives and join with others in the Drupal community to improve the Drupal software, translations, documentation, and the community itself. 

Whether you are new to contributing to the Drupal project and community, or are an experienced contributor looking for a new task or role, you can use the following entry points to explore the many possible ways you can contribute.

Create account on drupal.org and install

  1. We need to create an account on drupal.org for contribution 
  2. Go to drupal.org and click on create account, if you already have an account then login your account.
  3. Install drupal using composer 


Create a patch

  1. Go to the issues link in drupal.org. 


2. Select any issue from the list, read carefully and understand the problem.

3. Check module/theme/core version from issue.



4. After check version click on project link.



5. On project page click on version control, select version and click on show button.



6. Clone project in drupal setup (if module then clone in module/contrib folder), if you are working on theme then clone project in theme folder.



7. After clone make changes in core/module/theme’s any files for fix issue and please make sure code standard is correct according to drupal

8. Test on the local system and make sure issue is resolved, if issue is resolved then come back on terminal and go change directory in module/theme’s root.

9. Now run git diff command in terminal (for example i have made some changes in README.md file and run command).



10. Now we are going to make a patch file, patch file naming always in this format.

([description]-[issue-number]-[comment-number].patch)

a) Description : We can describe issue details

b) Issue-number : Issue number is last of url (https://www.drupal.org/project/cas/issues/3291020) 3291020 this is issue number.

c) Comment-number : Comment number mean is describe in screenshot.

11. So my patch naming will be like this test-patch-3291020-5.patch

12. Go to terminal and run command git diff > test-patch-3291020-5.patch

13. Now patch is ready, Now we need to upload this patch on the same issue page, change status need work to need review, go to bottom of issue and upload patch file and save.

Review and applying patch with composer

To begin, we need to add the “cweagans/composer-patches” plugin to aid us in patching modules. We can add this to Composer by typing in command line:

  1. Find any issue which have needs review status
  2. Install and enable module/theme 
  3. Open terminal at the root of project, and run command composer require cweagans/composer-patches
  4. Edit the composer.json file and add below these lines to the “extra”: object:

“extra”: {

    “enable-patching”: true,

    “patches”: {

        “drupal/core”: {

            “<patch1 information>”: “<patch1 file path>”

        },

         “drupal/libraries”: {

            “<patch1 information>”: “<patch1 file path>”

        }

     }

}

In the example above, we are patching to different modules, the Drupal core and libraries modules. Each separate module are defined separately on each line.

  1. Now we need to run command composer install

After composer install, some time composer.lock file might not updated with latest patch information. We can run the command below:

composer update –lock

This will update your composer.lock file and include any newer updates made to composer.json file.

  1. If there are multiple of patch files you want to include for the ‘same’ module, you group them together separated by a comma, like:

“extra”: {

    “enable-patching”: true,

    “patches”: {

        “drupal/core”: {

            “<patch1 information>”: “<patch1 file path>”,

            “<patch2 information>”: “<patch2 file path>”

        }

     }

}



To explore more about this deeply , You can further contact on info@virasatsolutions.com