@@ -217,9 +217,48 @@ user by dynamically rewriting the current page rather than loading entire new
217217pages from a server.
218218
219219By default, the debug toolbar displays the information of the initial page load
220- and doesn't refresh after each AJAX request. However, you can set the
221- ``Symfony-Debug-Toolbar-Replace `` header to a value of ``'1' `` in the response to
222- the AJAX request to force the refresh of the toolbar::
220+ and doesn't refresh after each AJAX request. However, you can configure the
221+ toolbar to be refreshed after each AJAX request by enabling ``ajax_replace `` in the
222+ ``web_profiler `` configuration:
223+
224+ .. configuration-block ::
225+
226+ .. code-block :: yaml
227+
228+ # config/packages/web_profiler.yaml
229+ web_profiler :
230+ toolbar :
231+ ajax_replace : true
232+
233+ .. code-block :: xml
234+
235+ <!-- config/packages/web_profiler.xml -->
236+ <?xml version =" 1.0" ?>
237+ <container xmlns =" http://symfony.com/schema/dic/services"
238+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
239+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
240+ xmlns : web-profiler =" http://symfony.com/schema/dic/webprofiler"
241+ xsi : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
242+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
243+
244+ <web-profiler : config >
245+ <web-profiler : toolbar ajax-replace =" true" />
246+ </web-profiler : config >
247+ </container >
248+
249+ .. code-block :: php
250+
251+ // config/packages/web_profiler.php
252+ use Symfony\Config\WebProfilerConfig;
253+
254+ return static function (WebProfilerConfig $profiler): void {
255+ $profiler->toolbar()
256+ ->ajaxReplace(true);
257+ };
258+
259+ If you need a more sophisticated solution, you can set the
260+ ``Symfony-Debug-Toolbar-Replace `` header to a value of ``'1' `` in the response
261+ yourself::
223262
224263 $response->headers->set('Symfony-Debug-Toolbar-Replace', '1');
225264
@@ -228,31 +267,21 @@ production. To do that, create an :doc:`event subscriber </event_dispatcher>`
228267and listen to the :ref: `kernel.response <component-http-kernel-kernel-response >`
229268event::
230269
270+ use Symfony\Component\DependencyInjection\Attribute\When;
231271 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
232272 use Symfony\Component\HttpKernel\Event\ResponseEvent;
233273 use Symfony\Component\HttpKernel\KernelInterface;
234274
235275 // ...
236276
277+ #[When(env: 'dev')]
237278 class MySubscriber implements EventSubscriberInterface
238279 {
239- public function __construct(
240- private KernelInterface $kernel,
241- ) {
242- }
243-
244280 // ...
245281
246282 public function onKernelResponse(ResponseEvent $event): void
247283 {
248- if (!$this->kernel->isDebug()) {
249- return;
250- }
251-
252- $request = $event->getRequest();
253- if (!$request->isXmlHttpRequest()) {
254- return;
255- }
284+ // Your custom logic here
256285
257286 $response = $event->getResponse();
258287 $response->headers->set('Symfony-Debug-Toolbar-Replace', '1');
0 commit comments