Drupal Contribution

Let's contribute code to Drupal.org an open source... community in a few steps. There are many ways get involved to the Drupal community Learn more  See more
Action Command
NEW MODULE
Contibute your own module to the community so that the world can use it (as a contrib module).
# First create a new Module Node
# Take an example case of Download On-The-Fly (download_otf) module
  1. Login to Drupal.org with your Drupal account
  2. Navigate My Account > Your Projects > Add a new project > Module Project [OR] Direct Link
  3. Provide module related inputs:
    • Name: Download On-The-Fly
    • Project Type: Select appropriate value
      • Full Project (Ready to use project)
      • Sandbox Project (Experimental code not yet ready to use)
    • Short (Machine Name): download_otf
    • Images: Upload supporting image that describes the Module (Optional)
    • Project Classification:
      • Maintenance status: Choose appropriate value
      • Development status: Choose appropriate value
      • Module Categories: Choose appropriate value
    • Description: Describe Module in detail
  4. Click SAVE
  5. Now we will land to project page say, https://www.drupal.org/project/<module_machine_name> with below message(s):
    • Module project <Module_Human_Readable_Name> has been created.
    • The Git repository for this project has been enqueued for creation. It should be available in a few seconds.
# Push the module code to the above newly generated Git repository
Check Contribute Custom Module

# Release your new module to the world
Check Release Module
CONTRIBUTE CUSTOM MODULE
Contributing code is an important and effective way to improve your learning, your code in various ways. Also, it is best to share your code with the world of open-source, so that one need not require to re-invent the wheel. So, if you think the custom module you have recently worked on has a generic solution and is re-usable, then contribute it today! Also check Contribution PTR

# Take an example case of my Download On-The-Fly (download_otf) custom module
# First you need to create a Module Node
Check New Module

# Be ready with the module's repository details created in previous step
Check Find Repository

# We believe that the custom module is ready and already installed locally
# Now, go to the respective module directory
cd /path/to/module

# Initialize git for collaboration
git init
git remote add origin git@git.drupal.org:project/download_otf.git

# Check remote once
git remote -v
origin git@git.drupal.org:project/download_otf.git (fetch)
origin git@git.drupal.org:project/download_otf.git (push)
# Create a new branch
git checkout -b 8.x-1.x

# Now, stage all module files and check the status
git add .
git status

# Before committing the code- configure Git with correct user name/email
Check Git Configuration

# Now, commit the code and check the commit logs
git commit -m "Initial Commit."
git log

# Push the branch code
git push -u origin 8.x-1.x

# Now, release your new module to the world
Check Release Module
MODULE REVISIT
(ADD NEW FEATURES)
Module repositories are public for collaboration. Owner or Maintainer of the project can push the code, whereas others can work on the shared code and create patch for adding new feature or bug fixes. Being owner of the module lets add new features to the module and release another version of the module.
# To begin with let's have our module already installed locally
# Take an example case of Download On-The-Fly (download_otf) module
# Now, go to the respective module directory
cd /path/to/module

# Now, get the module's branch & repository url
Check Find Repository & Branch Details

# Initialize git for collaboration
git init
git remote add origin git@git.drupal.org:project/download_otf.git

# Check remote once
git remote -v
origin git@git.drupal.org:project/download_otf.git (fetch)
origin git@git.drupal.org:project/download_otf.git (push)
# Switch to appropriate branch and pull the code
git checkout -b 8.x-1.x
git pull

At this point, we are ready to make changes to the module and test the working of the changes we made so far.
# Now, stage all the new/modified module files and check the status
git add .
git status

# Before committing the code- configure Git with correct user name/email
Check Git Configuration

# Now, commit the code and check the commit logs
git commit -m "Introducing external vendor library support for file data generation"
git log

# Push the branch code
git push -u origin 8.x-1.x

# Now, release your new module to the world
Check Release Module
RELEASE MODULE
Its time to release your module to the world. Module's are released at specified repository tags. Example, if we are interested in releasing 8.x-1.0 version of your module, then we will need to introduce 8.x-1.0 tag to the repository. Learn more on Git tags
# Once we are ready with committing all latest changes, check log once
git log

# Now, let's create and push a new annotated tag for our very first module release
# NOTE: While creating tag here- we are using ZERO in ‘8.x-1.0’ at the end, sometimes it clashes with branch name and causes issue
git tag -a 8.x-1.0 -m "First version of the module"
git push origin tag 8.x-1.0

# Can't wait but few more steps to follow:
  1. Login to Drupal.org with your Drupal account
  2. Click on ‘Add new release’ link at the very bottom of the respective module's page
    • Gitlab release tag or branch: Choose the created tag 8.x-1.0
    • Click NEXT
    • Release notes: Add release details
    • Short description: Add short description
      (This appears just above tar/zip download links on the page)
    • Release type: New features
  3. Click SAVE
  4. Come back to module's page and find your released Module. Hurray!
NEW ISSUE
If we face any issue or want to report bug let the Drupal community know. Not only bug we can also request a new module feature. To do so, we need to create a new issue.
  1. Login to Drupal.org with your Drupal account
  2. On modules page at the right region block under 'Issues':
  3. Search for issue before submitting a new issue to avoid duplicates
  4. Also, see 'All issues' already raised
  5. If no related issues found create a new one by clicking on 'Create a new issue'
  6. Provide inputs for the Issue form:
    • Title: Give suitable issue title
    • Category: Select appropriate option
    • Priority: Select appropriate option
    • Status: Active
    • Version: Select appropriate module version
    • Component: Select appropriate option
    • Assigned: If we are working on this issue then assign to self or leave it Unassigned
    • Issue Tags: Search issue related tags and add Issue
    • Summary: Describe the issue
    • File: Upload image or file that describes the issue (Generally used to share patch)
  7. Click SAVE
NEW PATCH
Patches should be submitted via the issue tracker, i.e., there should exists an issue against which a patch shall be submitted. Create A New Issue to report bug or request a feature and then only introduce a patch against it. Also, check what is Revised Patch? Learn more on Git Patch.
# To create patch it is best- that we have already installed the module locally
# Now, go to the respective module directory
cd /path/to/module

# Initialize a new git & stage all module files
git init
git add .
git status

At this point, make all your changes to the module files and test the working of the changes we made so far.
# Be ready with your patch file name
Check Naming Patch

# Now, create patch file, example
git diff --cached > download_otf_text_examples_3124918_7_D8.patch.patch

# Finally, submit the patch file
Check Submit Patch

# At last, if all looks good, remove .git folder and stop further tracking file changes
rm -rf .git
SUBMIT PATCH
It is advised to test patch files locally before submitting. Learn more on Git Patch. Once your patch and/or interdiff file(s) are ready and tested, submitting patch is an easy step.
  1. Login to Drupal.org with your Drupal account
  2. Go to respective issue page, and submit 'Add new comment' form:
    • Issue Metadata (Status): Needs Review
    • Comment: Add suitable comment
    • Files: Upload patch and/or interdiff file (one by one)
  3. Click SAVE
REVISED PATCH
Sometimes, against an issue, a patch is available but that is partial or some update is required. In this case, one can submit a revised patch. Learn more on Git Patch.
# To create patch it is best- that we have already installed the module locally
# Now, go to the respective module directory
cd /path/to/module

# Initialize a new git & commit all module files
git init
git add .
git status
git commit -m 'Module initial state.'

# Apply (available partial) patch & commit the changes, example:
curl https://www.drupal.org/files/issues/2020-04-04/download_otf_text_examples_3124918_2_D8.patch | git apply
git add .
git status
git commit -m 'Module state after applying existing patch.'

At this point, make all your changes to the module files and test the working of the changes we made so far.
# Be ready with your patch file names
Check Naming Patch

# Create patch & interdiff files, example:
git diff > interdiff-3124918-2-7.txt
git diff HEAD~1 > download_otf_text_examples_3124918_7_D8.patch.patch

# Finally, submit the patch & interdiff file
Check Submit Patch

# At last, if all looks good, remove .git folder and stop further tracking file changes
rm -rf .git
RESOLVE ISSUE
(OWNER/MAINTAINER)
Owner or Maintainer of the module can resolve the issue by applying patch and release a new version of the module. These patches might have been provided by some contributor or we can create on your own.
# To resolve a patch it is best- that we have already installed the module locally
# Now, go to the respective module directory
cd /path/to/module

# Now, get the module's branch & repository url
Check Find Repository & Branch Details

# Take an example case of Download On-The-Fly (download_otf) module
# Initialize git for collaboration
git init
git remote add origin git@git.drupal.org:project/download_otf.git

# Check remote once
git remote -v
origin git@git.drupal.org:project/download_otf.git (fetch)
origin git@git.drupal.org:project/download_otf.git (push)
# Switch to appropriate branch and pull the code
git checkout -b 8.x-1.x
git pull

# Now, its time to examine the available patch
Check Examine Patch

# Post patch examination, we should be at module's directory
pwd

# Now stage the changes, since, patch is already applied in Examine Patch step.
git add .

At this point, we are ready to commit and push the code, but wait! Resolving issue requires conventional commit message, check below steps.
  1. Login to Drupal.org with your Drupal account
  2. Go to respective issue page within 'Add new comment' form (DO NOT SUBMIT)
  3. Update Credit & committing section
    • Giving credit to:
      Opt checkboxes against the contributors (we want to credit to), and
      Opt (radio button) the patch author
    • Credit others could be used to search and credit other contributors as well
  4. Now, at the very bottom of the form copy the commit message under 'Git command' vertical tab.
  5. DO NOT Click SAVE
# Using above message, commit and push the code
git commit -m 'Issue #3124918 by abhaysaraf: How to use? (Working examples)' --author="abhaysaraf <git@2723079.no-reply.drupal.org>"
git push origin 8.x-1.x

# Now release a newer version of the module
Check Release Module

Huh! We are pending with one last important task. Which is updating the issue status on Drupal.org, along with crediting the patch contributor(s) for their time and effort. So, let's do that.
  1. Login to Drupal.org with your Drupal account
  2. Go to respective issue page, and submit 'Add new comment' form:
    • Update Issue Metadata section
      • Status: Fixed
      • Assigned: Unassigned
    • Update Credit & committing section
      • Giving credit to: Opt checkboxes against the contributors (we want to credit to)
      • Credit others could be used to search and credit other contributors as well
        Important: A comment for each contributor will be added and they will be notified
  3. Click SAVE
  4. Note: Issue will automatically get closed with status 'Closed (fixed)' in 2 weeks if no activity.
NAMING PATCH
A convention or nomenclature is followed to name patch files. This helps other contributors to collect patch information in a quick glance.
# Naming a patch file
{project_name}-{issue_short_detail}-{issue_nid}-{expected_next_comment_number}-{drupal_version}.patch
download_otf_text_examples_3124918_7_D8.patch.patch

# Naming an interdiff file
interdiff-{issue_nid}-{last_patch_comment_number}-{expected_next_comment_number}.txt
interdiff-3124918-2-7.txt

TIP:
Q. How to get 'issue_nid'?
-  Get it from issue page URL, as a issue number.
Q. How to get 'expected_next_comment_number'?
-  On the respective issue page, in the comment-form a number appears just after 'Add new comment #'.
Q. How to get 'last_patch_comment_number'?
-  It is the comment number of the patch against which we created a revised patch.
EXAMINE PATCH
It is good practice to test the patch files locally before submitting or resolving an issue. Learn more on How to apply Patch?. Additionally, Dreditor (Browser Extension) helps in quickly reviewing both patch & interdiff file in the respective issue page itself.
# To test a patch it is best- that we have already installed the module locally
# Now, go to the respective module directory
cd /path/to/module

# Apply the target patch
curl https://www.drupal.org/files/issues/2020-06-19/download_otf_text_examples_3124918_7_D8.patch.patch | git apply

At this point, patch has been applied successfully. And we are now required to test the working of the respective module locally. Your patch seems to be a valid patch if module behaviour is as per the expectation.
FIND REPOSITORY
Module repositories are public for collaboration. Drupal manages project repositories at git.drupalcode.org.
# Find module's repository & branch informations along with essential Git commands
  1. Visit Drupal.org
  2. Go to respective module's page
  3. Click on Version Control tab
  4. Here we will find repository and other details along with essential Git commands for working with the project
  5. Additionally, you can login with your Drupal account to explore more
# Find module's repository informations the way Github/GitLab shows
  1. Visit Git Drupal.org
  2. In search box, search with your module's machine name
  3. Select your module from the list to get overview and repository details
  4. Additionally, you can login with your Drupal account credentials to explore more
GIT AUTHENTICATION
Setting up SSH is recommended for authenticating with Drupal's Git repositories. Otherwise, while code collaboration Git will prompt you to authenticate using your Drupal account password Learn more.
# Setting up SSH requires SSH keys
Check SSH key

# Let's create one (Do not create if already exists)
ssh-keygen -t rsa -b 4096 -C Drupaldrug

# Now, copy public SSH key
cat ~/.ssh/id_rsa.pub

# Add Public SSH key to your Drupal account
  1. Login to Drupal.org with your Drupal account
  2. Navigate My Account > Profile > SSH keys (sub-tab) > Add a public key
  3. Title: Give appropriate key title
  4. Key: Paste here the copied 'Public SSH' key
  5. Click SAVE
Note: The very first time you try make git actions to drupal git-repositories; Your system does not know Drupal.org's public key and will prompt 'Are you sure you want to continue connecting (yes/no)?', be sure to type 'yes'.
GIT CONFIGURATION
It is important to configure Git using registered or anonymized email, or else you will not be credited in commit statistics or listings. Also check anonymized email .
# To find all your registered email IDs
  1. Login to Drupal.org with your Drupal account
  2. navigate to My Account > Profile > Edit (sub-tab) > E-mail addresses
Attention! Git allows to configure user details per project/repository basis or accross all projects in your machine. This can be updated at any point of time. Learn more
# Configure details particular to current project/repository
git config user.name "Your Name"
git config user.email "your email"

# Configure details globally, i.e., across all projects
git config --global user.name "Your Name"
git config --global user.email "your email"
SECURITY COVERAGE
It is advised to take security coverage for your contributed modules Learn more. While submitting your module, 'Opt into security advisory coverage' option remain disable for next 10 Days, then after, we can opt into this coverage following given steps.
  1. Login to Drupal.org with your Drupal account
  2. Click on ‘Edit’ tab on the concerned module's page
  3. Find 'Security advisory coverage' under Project Classification section
  4. Select 'Opt into security advisory coverage'
  5. Click SAVE
ANONYMYZED EMAIL
Drupal provisions an 'Anonymized Drupal Email' for collaboration. Since, Email addresses in Git repositories can be accessed by anyone looking at the Git log. Hence, as per your preference you can use an anonymized address instead of your real email address. Anonymized address look somewhat like 'git@2723079.no-reply.drupal.org'.
# Find your Anonymized email address
  1. Login to Drupal.org with your Drupal account
  2. Navigate My Account > Profile > Git access (sub-tab)
  3. Find it under 'Git Configuration' section
CONTRIBUTION PTR
Points to remember while contributing to the Drupal community.
Checklist [Module Contribution]
  1. Is file README.txt added?
  2. Is file composer.json (Composer support) added?

Comments

  1. https://www.drupal.org/docs/distributions/degov/semantic-versioning-model

    ReplyDelete
  2. MODULE REVISIT (ADD NEW FEATURES)

    UPTADE FROM:
    # Switch to appropriate branch and pull the code
    git checkout -b 8.x-1.x
    git pull

    TO:
    # Switch to appropriate branch and pull the code
    git checkout -b 8.x-1.x
    git add .
    git pull origin 8.x-1.x


    ReplyDelete
  3. # Take an example case of my Download On-The-Fly (download_otf) custom module
    # First you need to create a Module Node
    Check New Module

    # Be ready with the module's repository details created in previous step
    Check Find Repository

    # We believe that the custom module is ready and already installed locally
    # Now, go to the respective module directory
    cd /path/to/module

    # Initialize git for collaboration
    git init
    git remote add origin git@git.drupal.org:project/download_otf.git

    # Check remote once
    git remote -v
    origin git@git.drupal.org:project/download_otf.git (fetch)
    origin git@git.drupal.org:project/download_otf.git (push)
    # Create a new branch
    git checkout -b 8.x-1.x

    # Now, stage all module files and check the status
    git add .
    git status

    # Before committing the code- configure Git with correct user name/email
    Check Git Configuration

    Profile >> GIT ACCESS
    Get you no-reply email Email addresses in Git repositories can be accessed by anyone looking at the Git log. It is generally considered appropriate to use a real, public-facing email for Git. If you prefer to use an anonymized address, use:

    ReplyDelete
  4. https://drupaldrug.blogspot.com/2020/06/drupal-contribution.html#dd-heading-security-coverage
    This may take half a day to reflect. By that time you may see message on composer
    You are using Drupal packages that are not supported by the Drupal Security Team!
    - drupal/colorpalette:1.0.2.0: Project has not opted into security advisory coverage!

    ReplyDelete
  5. Make sure u have minimum
    module.info
    composer.json

    ReplyDelete
  6. See https://drupal.org/project/config_inspector for a module to help with debugging your schemas. The module helps find missing schemas and schema elements with various views on your data and schema.

    ReplyDelete
    Replies
    1. Code style to use for schema files https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata#codestyle

      Delete
    2. drush config:inspect --detail --only-error

      Delete
  7. Security issues should not be reported as a general issue. Follow the procedure for reporting security issues https://www.drupal.org/node/3156997.

    ReplyDelete
  8. Semantic Versioning -- MAJOR.MINOR.PATCH -- https://semver.org/

    ReplyDelete

Post a Comment

Drupal Contribution
Git Commands
RESTful Services
Lando Commands
Docker Commands
MySQL
Database Quick Code
Drush Commands
Drupal Console
PHP Quick Code
Drupal Quick Code
Composer Commands
Linux Commands
Linux Shell Scripting
Drupal Hooks
Twig Tricks
PHPUnit Test
PhpMyAdmin
Drupal Constants
CSS Clues
BLT Commands
Vagrant Commands
Localhost
127.0.0.1
Drupal Interview
Drupal Certifications
Concept & Definitions
Mac Tips
Windows Tips
Browser Tips

Best Practice

Use 'elseif' instead of 'else if'
#CodingTips

As of PHP 5.4 you can also use the short array syntax, which replaces array() with []
#CodingTips

Functions in general shall be named using snake_case(say, my_function()), and using camelCase(say, myFunction()) when declared within a plugin class
#CodingTips

Variables in general shall be named using snake_case(say, $my_variable), and using camelCase(say, $myVariable) when declared within a plugin class
#CodingTips

Manage automatically assigning of new permissions whenever a module is enabled here- admin/config/people/accounts
#ConfigurationTips

Manage source of Main-menu and User-menu links here- admin/structure/menu/settings
#ConfigurationTips

Helper function(s) shall be named prefixing an underscore(say, _my_helper_function()), which can prevent hooks from being called
#CodingTips

Ideally, configuring of 'Private file system path' at admin/config/media/file-system should be located outside of your Drupal root folder(say, ../my_private_files)
#ConfigurationTips

You should be aware that uploading files as 'Private file' will slow down the process of loading the files as Drupal has to be bootstrapped for every file that needs to be downloaded
#ConfigurationTips #BeAware

Code should always be pushed up(dev -> staging -> production) and databases should only be pushed down(production -> staging -> dev)
#DevelopmentTips

Get Raw SQL Query of drupal dynamic queries before executing it using $query->__toString();
#DebugTips

In VI-Editor, Press ESC key to come in command mode and for undo type :U and for redo type :Ctrl+R
#LinuxTips

Insert queries must always use a query builder object(layer of abstraction), allowing individual database drivers special handling for column values (if applicable), example case for LOB and BLOB fields.
#DatabaseQueryTips

Drupal uses the .inc extension to prevent files from being executed directly.
#DevelopmentTips

Popular Posts