Skip to main content

Add a New Module

In step five of the Build Tools guide, learn how to add new modules to your site.


Next, we'll add a module to our existing slogan branch using Composer. You should already have a Pull Request open for this branch in GitHub, created in a previous lesson.

Local Setup

This section will be performed from the command line, to prepare your local system.

  1. Navigate to the Code tab of the GitHub repository, then click Code and copy the repository URL:

    Click Code and copy the repository URL

  2. Open a terminal application and clone the GitHub repository (replace <github-url>):

    git clone <github-url>
  3. Navigate to the repository's root (replace pantheon-d8-composer-project):

    cd pantheon-d8-composer-project
  4. Install dependencies with Composer:

    composer install
  5. Export local environment variables to define your site name and Multidev environment to easily copy and paste example commands in the next sections (replace pantheon-d8-composer-project):

    export SITE=pantheon-d8-composer-project
      export ENV=ci-4

Install a Contrib Module

  1. Use Composer locally to add the Pathauto module as a dependency on the existing slogan branch:

    git checkout slogan
      composer require drupal/pathauto

    Note that the dependencies of pathauto, token and ctools, are also installed:

    Composer require pathauto

  2. Commit the updated composer.json and composer.lock files and push your work to the slogan branch on GitHub:

    git add composer.*
      git commit -m "Install drupal/pathauto ^1.0"
      git push origin slogan

    Commit composer.json and composer.lock

  3. Enable the Pathauto module on the Pantheon Multidev environment from the command line using Terminus and Drush:

    terminus drush $SITE.$ENV -- pm-enable pathauto --yes
  4. You can use the method described in an earlier lesson to export configuration changes made in the last step or you can do it from the command line using Terminus and Drush:

    terminus drush $SITE.$ENV -- config-export --yes
  1. Commit your changes in Pantheon from the command line with Terminus:

    terminus env:commit $SITE.$ENV --message="Install and enable pathauto"

    enable export config and commit

Use this process to install any new dependency required by your project. The site should never use Drupal's Extend -> Install new module feature or drush pm-download, as neither of these techniques modify the composer.json file. Modules added using these methods will disappear the next time the build artifacts are pushed to your Pantheon Multidev environment. You must use Composer to install new modules exclusively.