Skip to main content

Receive up to 30% off your quote. request a quote now

How to easily create a patch for a Drupal module

How to easily create a patch for a Drupal module

How to easily create a patch for a Drupal module

To help reviewers understand the scope of changes, separate each change type into its own issue, each with its own patch or merge request. For example, bug fixes, performance enhancements, code style fixes, and whitespace fixes all should be in different issues. Each separate change type should be associated with a different issue in the queue on Drupal.org.
 

Drupal.org has used patches to manage community contributions for many years. But, patches are difficult for new users to learn and require the use of the command line. Recently, Drupal.org code has migrated to Gitlab, and we can now use Gitlab and Drupal.org issues to create merge requests to share code and fixes with modules and Drupal Core. But, how do you use the code on your site immediately?

First, make sure your issue is not already reported by someone else in the issue queue for the module. Also, check out the latest dev version of the module, is the issue resolved there? and following  the steps below :

  1. Set up prerequisites: Login, Local development site (optional), and Git from Common Prerequisites for Contributors.

  2. Find an issue with the status Active or Needs work in the Drupal core project, or a contributed module, theme, or distribution project that you are familiar with. If the issue already has an issue fork or merge request created, you should make a merge request instead of a patch. Also, if the issue is complex and you think many people might want to collaborate on the fix, you should use a merge request. If either of those is the case, follow the steps in the Create a merge request task instead of this task write-up.

  3. Read the issue, making sure you understand the Problem and the Proposed Resolution sections of the issue summary, or equivalent information. If the issue summary is incomplete or outdated, see the Write an issue summary task.

  4. Add a comment to the issue saying that you are creating a patch for the issue.

  5. Use Git to clone or update the repository for the project, and check out the version you are creating the patch for. Then make a local branch in your Git repository to work on the patch. See the "Prepare the local repository" section of Making a patch for details.

  6. Edit the code base with the changes necessary to resolve the issue, following the idea in the Proposed resolution section of the summary. Make sure to follow the Drupal project coding standardsinterface text standards, and documentation standards. If you are working in the Drupal core project, the page Figuring out what Drupal core code to patch may be helpful. If the issue needs an automated test to be written, see the task writeup on automated tests.

  7. Make a patch that contains the changes you made to the code base.

  8. If the issue already had a patch that you are updating, make an interdiff between the existing patch and your new patch.

  9. Attach the patch (and interdiff) to the issue. Change the issue status to Needs review. Add a comment that explains the changes you made, and modify the issue summary as necessary. Click Save on the issue, to save your files, comment, and issue field changes.

  10.  
Do you have any project ?

Let’s Talk Business Solutions With You