Configuring Environment Indicators

Learn how to implement an environment indicator for Drupal and WordPress sites running on Pantheon.

Contributors: Whitney Meredith.

Discuss in our Forum Discuss in Slack

This section provides information on how to install an indicator to receive alerts when changes are made in your site and environments.

We recommend installing the Pantheon HUD plugin on WordPress sites and the Environment Indicator module on Drupal sites.

 Exports

This doc uses Terminus example commands with common variable names for the site and environment names. Before you begin these steps, set the variables $site and $env in your terminal session to match your site name and the Dev (or Multidev) environment:

export site=yoursitename
export env=dev #or Multidev name

WordPress: Pantheon HUD

The Pantheon HUD plugin is developed and maintained on GitHub. Create an issue with questions, feature requests, or bug reports.

  1. Set the connection mode to SFTP for the Dev or Multidev environment via the Pantheon Dashboard or with Terminus:

    terminus connection:set $site.$env sftp
  2. Install and activate Pantheon HUD from within the Dev or Multidev environment's WordPress Dashboard (/wp-admin/plugin-install.php?tab=search&s=pantheon+hud) or with Terminus:

    terminus wp $site.$env -- plugin install pantheon-hud --activate
  3. Deploy the plugin to the Test environment within the Site Dashboard or with Terminus, and clear the site cache:

    terminus env:deploy $site.test --sync-content --updatedb --note="Install Pantheon HUD plugin"
    terminus env:clear-cache <site>.test

    If you're working from a Multidev environment, merge to Dev first.

  4. Activate the plugin within the WordPress Dashboard on the Test environment (/wp-admin/plugins.php) or with Terminus:

    terminus wp $site.test -- plugin activate pantheon-hud
  5. Deploy the plugin to the Live environment within the Site Dashboard or with Terminus, and clear the site cache:

    terminus env:deploy $site.live --note="Install Pantheon HUD plugin"
    terminus env:clear-cache <site>.live
  6. Activate the plugin within the WordPress Dashboard on the Live environment (/wp-admin/plugins.php) or with Terminus:

    terminus wp $site.live -- plugin activate pantheon-hud

All environments will now show the following indicator for users who are logged in with the manage_options capability:

Pantheon HUD

You can restrict this to specific users with the pantheon_hud_current_user_can_view filter:

add_filter( 'pantheon_hud_current_user_can_view', function(){
    $current_user = wp_get_current_user();
    if ( $current_user && in_array( $current_user->user_login, array( 'myuserlogin' ) ) ) {
        return true;
    }
    return false;
});

Drupal: Environment Indicator

The Environment Indicator module is officially supported for Drupal 7 sites.

  1. Set the connection mode to SFTP for the Dev or Multidev environment via the Pantheon Dashboard or with Terminus:

    terminus connection:set $site.$env sftp
  2. Install and enable the Environment Indicator module using the Drupal interface or with Terminus:

    terminus drush $site.$env -- en environment_indicator -y
  3. Add the following within settings.php for Drupal 7:

    /*
    * Environment Indicator module settings.
    * see: https://pantheon.io/docs/guides/environment-configuration/environment-indicator
    */
    
    $conf['environment_indicator_overwrite'] = TRUE;
      $conf['environment_indicator_overwritten_position'] = 'top';
      $conf['environment_indicator_overwritten_fixed'] = FALSE;
    
      if (!defined('PANTHEON_ENVIRONMENT')) {
          $conf['environment_indicator_overwritten_name'] = 'Local';
          $conf['environment_indicator_overwritten_color'] = '#505050';
          $conf['environment_indicator_overwritten_text_color'] = '#ffffff';
      }
      // Pantheon Env Specific Config
      if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
          switch ($_ENV['PANTHEON_ENVIRONMENT']) {
            case 'lando': // Localdev or Lando environments
              $config['environment_indicator.indicator']['name'] = 'Local Dev';
              $config['environment_indicator.indicator']['bg_color'] = '#990055';
              $config['environment_indicator.indicator']['fg_color'] = '#ffffff';
              break;
            case 'dev':
              $conf['environment_indicator_overwritten_name'] = 'Dev';
              $conf['environment_indicator_overwritten_color'] = '#307b24';
              $conf['environment_indicator_overwritten_text_color'] = '#ffffff';
              break;
            case 'test':
              $conf['environment_indicator_overwritten_name'] = 'Test';
              $conf['environment_indicator_overwritten_color'] = '#b85c00';
              $conf['environment_indicator_overwritten_text_color'] = '#ffffff';
              break;
            case 'live':
              $conf['environment_indicator_overwritten_name'] = 'Live!';
              $conf['environment_indicator_overwritten_color'] = '#e7131a';
              $conf['environment_indicator_overwritten_text_color'] = '#ffffff';
              break;
            default:
              //Multidev catchall
              $conf['environment_indicator_overwritten_name'] = 'Multidev';
              $conf['environment_indicator_overwritten_color'] = '#e7131a';
              $conf['environment_indicator_overwritten_text_color'] = '#000000';
              break;
          }
      }
  4. Deploy the module to the Test environment within the Site Dashboard or with Terminus, and clear the site cache:

    terminus env:deploy $site.test --sync-content --updatedb --note="Install and configure Environment Indicator"
    terminus env:clear-cache <site>.test

    If you're working from a Multidev environment, merge to Dev first. Remember that the module will need to be activated again for each new environment.

  5. Deploy the module to the Live environment within the Site Dashboard or with Terminus, and clear the site cache:

    terminus env:deploy $site.live --updatedb --note="Install and configure Environment Indicator"
    terminus env:clear-cache <site>.live

All environments will now show a color-coded environment indicator, as defined within the above settings.php snippet.

More Resources