From e7c7767215c4ddb7c0cfb3376ef653025dd16973 Mon Sep 17 00:00:00 2001 From: boo-code Date: Wed, 2 Sep 2026 22:08:53 +0200 Subject: [PATCH] Say which container $this->get() resolves against in the front office The Symfony Services section describes config/services.yml and $this->get() without saying they only apply to the back office and to migrated pages. The front office caveat is further down the page, under Services in Legacy environment, which is where readers land only after the call has already failed. --- modules/concepts/services/_index.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/concepts/services/_index.md b/modules/concepts/services/_index.md index 30b3d37726..e1c51151a5 100644 --- a/modules/concepts/services/_index.md +++ b/modules/concepts/services/_index.md @@ -8,6 +8,20 @@ weight: 8 ## Symfony Services +{{% notice warning %}} +**`$this->get()` resolves against the container of the context you are in, which is not always the full Symfony container.** + +In the back office, and in pages already migrated to Symfony, you get the full container: `router`, `translator` +and anything you declared in `config/services.yml` are available. A front office page still runs a legacy +controller, and there `$this->get()` resolves against the light front container instead. It holds Doctrine and +the services declared in `/config/services/front/`, and nothing else: asking it for `router` or +`translator` raises a `ServiceNotFoundException`, `$this->getTwig()` returns `null`, and +`SymfonyContainer::getInstance()` is `null` there too. + +A service you want to call from a front office hook has to be declared in your module's `config/front/` folder. +See [Services in Legacy environment](#services-in-legacy-environment) below. +{{% /notice %}} + You have the ability to modify the Symfony container configuration from a module. This means that - You have the possibility to define your own Symfony services from your modules.