Skip to main content
Last Reviewed: December 12, 2022

Add Contrib and Custom Code


This section describes how to replicate your selection of contributed modules and themes, and any custom modules or themes your development team has created in your new project structure.

Contributed Code

The goal of this process is to have Composer manage all the site's contrib modules, contrib themes, core upgrades, and libraries (referred to as contributed code). The only items from the existing site that should remain in the Git repository are custom code, custom themes, and custom modules that are specific to the existing site.

Modules and Themes

Your site should already be managing contributed modules and themes through Composer. Follow the steps below to migrate these items to a new site.

  1. Open the source site composer.json.

  2. Run a composer require command for each module and theme in the $DESTINATION directory:

    composer require drupal/PROJECT_NAME:^VERSION

You can require multiple packages in the same commands, if desired.

Other Composer Packages

If you added non-Drupal packages to your site via Composer:

  1. Run the command composer require to migrate each package.

  2. Use the following command to display the differences between the master and current composer.json:

    diff -Nup --ignore-all-space $SOURCE/composer.json $DESTINATION/composer.json

Libraries

Libraries can be handled similarly to modules, but the specifics depend on how your library code was included in the source site. If you're using a library's API, you may have to do additional work to ensure that it functions correctly.

Custom Code

Manually copy custom code from the existing site repository to the Composer-managed directory.

Modules and Themes

git checkout master modules/custom
git mv modules/custom web/modules/
git commit -m "Copy custom modules"

settings.php

git status # Ensure working tree is clean
git show master:sites/default/settings.php > web/sites/default/original-settings.php
diff -Nup --ignore-all-space web/sites/default/settings.php web/sites/default/original-settings.php
# edit web/sites/default/settings.php and commit as needed
rm web/sites/default/original-settings.php

Additional Composer Configuration

Any additional Composer configuration that you have added to your site should be ported over to the new composer.json file. This can include configurations related to repositories, minimum-stability, or extra sections.

Use the diff command to get the information you need to copy:

diff -Nup --ignore-all-space $SOURCE/composer.json $DESTINATION/composer.json

Commit your changes as needed.

Push to the External Repository Master Branch

  1. Push to the master branch in the external repository:

    git push origin master
  2. Confirm that the Continuous Integration workflow succeeds in committing your code changes to the Pantheon site.