Change record status: 
Project: 
Introduced in branch: 
11.1.x
Introduced in version: 
11.1.0
Description: 

Drupal utilizes the Symfony service container, however some features such are not leveraged in Drupal 11.

Drupal now supports the decoration_on_invalid property. The Symfony documentation describes how it can be used.

When you decorate a service that doesn't exist, the decoration_on_invalid option allows you to choose the behavior to adopt.

Three different behaviors are available:

  • exception: A ServiceNotFoundException will be thrown telling that decorator's dependency is missing. (default)
  • ignore: The container will remove the decorator.
  • null: The container will keep the decorator service and will set the decorated one to null.

For example to ignore a service definition if the decorated service does not exist, in your modulename.services.yaml file you'd do:

Bar:
    decorates: DoesNotExist
    decoration_on_invalid: ignore
    arguments: ['@.inner']
Impacts: 
Module developers
Themers
Site templates, recipes and distribution developers