Environment Indicator
Adds visual cues to indicate which environment you are currently viewing (Development, Staging, Production, etc.).
environment_indicator
インストール
composer require 'drupal/environment_indicator:^4.0'
概要
Environment Indicatorは、サイトインターフェース全体に視覚的なインジケーターを追加することで、開発者やサイト管理者が現在作業している環境を常に把握できるようにします。これは、開発環境、ステージング環境、本番環境など、サイトの複数のコピーを管理する際に特に便利です。
このモジュールは、環境名とオプションのリリースバージョン情報を含むカラーバーをページ上部に表示します。また、Drupalの管理ツールバーの背景色を変更したり、サイトのファビコンにカラーオーバーレイを追加したりすることもできます。これらの視覚的インジケーターにより、現在の環境が一目で分かるため、本番サイトへの誤った変更を防ぐのに役立ちます。
Environment Indicatorには、環境スイッチャー機能も備わっており、ユーザーは異なる環境(例:ステージングから本番へ)の同じページにすばやく移動できます。各環境の色とURLは、切り替え先として設定できます。
設定は通常settings.local.phpで行われ、各環境がデータベースに環境固有の設定を保存することなく、独自のカラースキームを持つことができます。これはDrupalの環境固有設定のベストプラクティスに従っています。
Features
- 環境名を表示するカラーインジケーターバーをページ上部に表示
- ツールバーの背景色とテキスト色を環境に合わせて変更(Toolbar Integrationサブモジュールが必要)
- Tinyconライブラリを使用してサイトのファビコンにカラーオーバーレイを追加
- 複数のソース(Environment Indicator state、Deployment Identifier、またはDrupalバージョン)からバージョン/リリース識別子を表示
- 異なる環境の同じページにすばやく移動できる環境スイッチャー機能
- 各環境の前景色と背景色を設定可能
- 個別の環境インジケーターに対する動的なパーミッション
- 水平および垂直ツールバーモードを含むGin管理テーマとの完全な統合
- バージョン管理外の環境固有設定のためのsettings.local.phpでの設定
Use Cases
Multi-environment Development Workflow
When working with Development, Staging, and Production environments, configure each with distinct 'stoplight' colors: green for Development (changes are safe), yellow for Staging (exercise caution), and red for Production (be very careful). This visual system immediately alerts developers to which environment they're viewing, preventing accidental changes to production.
Quick Environment Switching
Configure environment switcher entities for all your environments. When viewing content on staging and need to check the same page on production, click the environment indicator to reveal the switcher menu and jump directly to the same path on the target environment.
Release Version Tracking
Display the current deployment version in the indicator using Drush: drush state:set environment_indicator.current_release v1.2.44. This helps team members verify which version is deployed to each environment without checking server files or deployment logs.
Client Presentation Mode
Use the Environment Indicator UI submodule to configure environment settings through the admin interface. This is useful when presenting to clients on staging environments where you want them to see a clear 'Staging' indicator without requiring PHP file access.
Tips
- Use different colored favicon overlays to distinguish browser tabs when multiple environments are open simultaneously
- Set the current release via deployment scripts: drush state:set environment_indicator.current_release $GIT_TAG
- Export environment switcher entities via config management so all environments have links to switch between each other
- For accessibility, ensure foreground and background colors have sufficient contrast ratio (WCAG 2.0 AA requires 4.5:1 for normal text)
- Consider using the UI submodule on environments where you cannot edit settings.local.php directly
Technical Details
Admin Pages 4
/admin/config/development/environment-indicator
Configure global settings for the Environment Indicator module, including favicon overlay and version identifier source.
/admin/config/development/environment-indicator/switcher
Manage environment switcher destinations. Create entries for each environment you want to be able to switch to. Each environment can have its own name, URL, and color scheme.
/admin/config/development/environment-indicator/switcher/add
Create a new environment switcher entry to allow jumping to another environment.
/admin/config/development/environment-indicator/current
Configure the current environment's display settings through the admin UI instead of settings.local.php. Provided by the Environment Indicator UI submodule.
権限 4
Troubleshooting 5
Ensure the user has the 'See all environment indicators' permission. Check that environment_indicator.indicator config has a 'name' value set either via settings.local.php or the UI submodule.
Verify settings.local.php is being loaded by uncommenting the include lines at the bottom of settings.php. Check for PHP syntax errors using: php -l settings.local.php
Enable the Environment Indicator - Toolbar Integration submodule (environment_indicator_toolbar). The main module only shows a colored bar; toolbar integration requires the separate submodule.
Grant the 'View environment indicator current release' permission to the user role. Verify the version identifier source is set correctly in settings and the source has a value (e.g., state set via Drush, deployment_identifier in settings.php, etc.)
Ensure 'Show favicon' is enabled in the module settings. Check that the Tinycon library is loading properly in browser developer tools. Some browsers may block favicon modifications.
Security Notes 3
- Environment switcher URLs should use HTTPS to prevent information leakage about internal environment URLs
- Consider restricting 'See all environment indicators' permission to authenticated users only to avoid revealing environment information to anonymous visitors
- The 'administer environment indicator settings' permission allows full configuration access and should be restricted to trusted administrators