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.

Modules

On the composerify branch, make a list of the modules that will need to be re-added:

  • If you know that all the sites have the same contrib and custom modules, get the list of modules from a single representative site. You will need this list in next steps:

    terminus drush $SITE.dev  -- pm-list --type=module --no-core --status=enabled
  • If you do not know whether the sites have the same contrib and custom modules installed, audit the modules across all sites and compile a unified list:

    Audit Contrib and Custom Modules
    1. To audit modules on all sites, create a new file called audit_site_modules.sh with the following content:

      audit_site_modules.sh
      #!/usr/bin/env bash
      
      echo 'Updating site list now with site urls from the custom Drupal Upstream.'
      SITES=$(terminus site:list --upstream=a2457b48-2c68-4d01-b471-7ae1337c9320 --field=Name)
      
      for site in $SITES
      do
        echo "---------- $site -----------"
        terminus drush $site.dev  -- pm-list --type=module --no-core --status=enabled
        echo "----------------------------"
        echo
      done | tee d8_upstream_sites_modules.txt
      
      for site in $SITES
      do
        echo "---------- $site -----------"
        terminus drush $site.dev  -- pm-list --type=theme --no-core --status=enabled
        echo "----------------------------"
        echo
      done | tee d8_upstream_sites_themes.txt
    2. Make the script executable:

      chmod +x audit_site_modules.sh
    3. Run the script:

      ./audit_site_modules.sh
      • This creates two new files in the same folder:

        • d8_upstream_sites_modules.txt: list of modules from each site
        • d8_upstream_sites_themes.txt: list of themes from each site
    4. Go through these files and build a list of modules and themes you'll need to add to the codebase.

Contrib Modules and Themes

  1. In your terminal, from the composerify branch, cd to upstream-configuration:

    cd upstream-configuration
  2. For each contrib module and theme in the list you've gathered

    1. Add the package and version with Composer. If the version starts with 8.x-, remove that and only include the version number after 8.x-.

      For example, if the version is 8.x-3.2, use the version number 3.2:

      composer require drupal/MODULE_NAME:^VERSION --no-update
    2. Confirm that only composer.json has been modified:

      git status
      • If anything other than composer.json has been modified, add the modified file to .gitignore.
    3. Commit the change:

      git commit -am "Adding MODULE_NAME"

Custom Modules and Themes

To move modules, use the following commands:

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

To move themes, use the following commands:

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