Skip to main content

Patch creating process

A Module from drupal.org can be installed manually or with the composer tool, which supposes to be already installed on your server.

A Module is a software that needs to be maintained from time to time, it even has fixes for the current features, and sometimes new features, some of the major updates will come as a normal module update, and can be done via the upgrade page, but sometimes there is a need for fast push of small fix, this is called patch.

Every change made by the developer has a scope of change, which should be separated by the specific issues that lead to this code fixing. the issue owns a patch that will be later on merged into the module release. Bug fixes, performance enhancements, and more, all should be in different issues.

Patches are difficult for new users to learn and handle, it require manual update of the module files, it said that there is an option for command line, but also recently, drupal.org migrated it to Gitlab, and we can use it to create merge requests to share code and fixes.

First of all, how to open an issue?

  1. Please make sure the issue is not already reported
     
  2. Check the latest dev version, maybe the issue doesn't exist anymore
     
  3. Open an Issue under the module issue list

 

Second, how to create a fix and patch?

  1. Set up prerequisites: login, local development site 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.