Skip to main content
Last Reviewed: June 22, 2021

Add Contrib and Custom Code

Learn how to 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.

Composer packages

  1. Copy your package list from the requires section of the existing site's composer.json and add it to the new site's composer.json.

    • If the existing composer.json defines additional repositories or patches, copy those over too. Take care not to overwrite the upstream-configuration package and repository.

    • If the old site has custom patches in its codebase, make sure to copy those over as well.

  2. Run composer update to have Composer create a composer.lock file with all versions and dependencies:

    composer update
  3. Run the git status command to confirm that all changed files have names that start with composer..

  4. Add other folders to .gitignore until git status only shows the Composer files being modified:

    git status
  5. Add and commit the changed Composer files to Git:

    git add composer.*; git commit -m "Add composer packages"

Custom Code

Complete the steps below if you have custom code that you would like to move to your new site.

  1. Manually copy custom code from the old site to the corresponding Pantheon site directory and commit the changes.

  2. Update the new .gitignore file to keep it aligned with the current site to avoid potential issues in the future.

Install Libraries with drupal-library

Do not add anything to web/libraries if you want to install libraries using Composer via a drupal-library project. Use must use Composer to install your libraries.

  1. Add each directory to be allowed (not ignored) by .gitignore if you commit libraries directly to web/libraries.

    • For example, to commit a favorite-library directory, add it and each directory to .gitignore.
  2. Run the git add command:

    .gitignore
    !/web/libraries/favorite-library
    !/web/libraries/other-favorite-library

You can remove the web/libraries line from the .gitignore file if you do not plan on adding any libraries with Composer in the future. This might lead to builds failing in the future if you or another developer use Composer to add a library later on.

Modules and Themes

Follow the steps below if you want to move modules and themes to your new site.

  1. Navigate to the Pantheon site directory.

  2. Copy modules from the local directory of the old platform site:

    cp -R ../FORMER-PLATFORM/modules/custom web/modules
    git add web/modules/custom
    git commit -m "Copy custom modules"
  3. Copy themes from the local directory of the old platform site:

    cp -R ../FORMER-PLATFORM/themes/custom web/themes
    git add web/themes/custom
    git commit -m "Copy custom themes"
  4. Copy any other custom code you need from your old platform site.

settings.php

Your existing site may have customizations to settings.php or other configuration files.

  1. Copy the existing settings.php to the Pantheon site and remove the $databases array if it exists.

  2. Ensure that everything in the Pantheon settings.php is included.

  3. Confirm that the settings.php file on the Pantheon D9 site:

    • Has one $settings['container_yamls'][]
    • Contains no duplicates
    • Contains include __DIR__ . "/settings.pantheon.php";

Configuration

Complete the steps in this section to copy exported configuration settings from the original site to your new Pantheon site.

  1. Navigate to your Pantheon site.

  2. Run the following commands:

    mkdir config
    cp -R ../FORMER-PLATFORM/<config folder location> config/
    git commit -m "Add site configuration."