Skip to main content
drupalreleases
Release: Cms 2.2.3 — Update released for Drupal core (2.2.3)! Release: Easy Breadcrumb 2.0.11 — Minor update available for module easy_breadcrumb (2.0.11). Release: Menu Link Attributes 8.x-1.9 — Minor update available for module menu_link_attributes (8.x-1.9). Release: Bootstrap 8.x-3.42 — Minor update available for theme bootstrap (8.x-3.42). Release: PhotoSwipe - Responsive JavaScript Modal Image Gallery 5.0.11 — Minor update available for module photoswipe (5.0.11). Release: Search API attachments 10.0.13 — Minor update available for module search_api_attachments (10.0.13). Release: amazee.ai Private AI Provider 1.4.6 — Minor update available for module ai_provider_amazeeio (1.4.6). Release: amazee.ai Private AI Provider 1.3.10 — Minor update available for module ai_provider_amazeeio (1.3.10). Module Revived: Bootstrap 8.x-3.41 — Theme bootstrap updated after 6 months of inactivity (8.x-3.41). Security Coverage: Component Library — Module component_library now has official Drupal security advisory coverage.

Limit services per environment

No security coverage Drupal 11 · not 10
View on drupal.org

This module allows you to conditionally enable or disable Drupal services based on the current environment, helping to use different service implementations for different environments without adding conditional logic to your code.

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.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jun 2026
Latest release
3 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core Release date
1.0.0 Stable 11 Jun 25, 2026