Problem/Motivation
The ToolbarHandler
service currently contains logic that is unrelated to toolbar rendering, specifically:
getCurrentRelease()
– retrieves the current release from state
getVersionIdentifier()
– provides a fallback identifier such as a Git hash or hostname
getTitle()
– formats the environment name and version identifier together
This logic is not specific to the toolbar, and may be used in other contexts (e.g. page top, navigation, system status, logging, etc.). Keeping it in the toolbar service ties general-purpose functionality to a specific UI implementation and makes it difficult to reuse or test independently.
This is part of a larger effort to extract non-toolbar logic from ToolbarHandler
and eventually deprecate that service in favor of dedicated submodules.
Steps to reproduce
Not applicable. This is not a bug, but an architectural improvement.
Proposed resolution
Create a new service class: EnvironmentIndicatorContext
in the Drupal\environment_indicator\Service
namespace.
Move the following methods from ToolbarHandler
to this new class:
getCurrentRelease()
getVersionIdentifier()
getTitle()
This service will act as a centralized context provider for the active environment indicator, and be responsible for formatting identifiers or names used in UI display or logging.
Update any consumers to use the new service:
\Drupal::service('environment_indicator.context')->getTitle();
Remaining tasks
- Create
EnvironmentIndicatorContext
class
- Move
getCurrentRelease()
, getVersionIdentifier()
, and getTitle()
to the new service
- Register
environment_indicator.context
in services.yml
- Inject any required dependencies (e.g.,
StateInterface
, ConfigFactoryInterface
, or active config)
- Update all internal calls to use the new service
- Add class-level docblock describing the purpose and scope of the context service
User interface changes
None.
API changes
Adds a new internal service: environment_indicator.context
No public API is removed.
Data model changes
None.