Drupal is a registered trademark of Dries Buytaert
drupal 10.6.12 Update released for Drupal core (10.6.12)! drupal 11.3.13 Update released for Drupal core (11.3.13)! drupal 10.6.11 Update released for Drupal core (10.6.11)! drupal 11.3.12 Update released for Drupal core (11.3.12)! drupal 11.2.14 Update released for Drupal core (11.2.14)! drupal 10.5.12 Update released for Drupal core (10.5.12)! cms 2.1.3 Update released for Drupal core (2.1.3)! drupal 10.5.11 Update released for Drupal core (10.5.11)! drupal 11.3.11 Update released for Drupal core (11.3.11)! drupal 11.2.13 Update released for Drupal core (11.2.13)! drupal 10.6.10 Update released for Drupal core (10.6.10)! cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)!

This module allows you to enable or disable Drupal services based on the current environment, inspired by Symfony's per-environment service configuration.

This is useful when you need different service implementations per environment — for example, using a real API client in production and a logger or mock in development/staging, without conditional logic in your code.

Features

  • #[ConditionalServices\Attribute\WhenEnv] — register a service only when DRUPAL_ENV matches a given value
  • #[ConditionalServices\Attribute\WhenNotEnv] — register a service only when DRUPAL_ENV does NOT match a given value
  • Works with any service tagged with kernel.event_subscriber, logger, or custom tags via tags attribute parameter

Requirements

Set the DRUPAL_ENV environment variable to any string identifying your environment (e.g. production, development, staging).

Examples

The module includes a conditional_services_examples submodule with sample controllers and services demonstrating both attributes in action.

Activity

Total releases
1
First release
Jun 2026
Latest release
20 hours ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.0 Stable Jun 25, 2026