Problem/Motivation
The Symfony dispatch() method notifies all listeners of the given event. It takes two arguments: the Event instance to pass to each listener of that event and the name of the event to dispatch.
https://git.drupalcode.org/project/csp/-/blob/8.x-1.x/src/EventSubscribe... gives this error when webprofiler module is enabled.
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" must be an object, string given. in Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch() (line 84 of modules/contrib/webprofiler/src/EventDispatcher/TraceableEventDispatcher.php).
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch('csp.policy_alter', Object) (Line: 178)
Drupal\csp\EventSubscriber\ResponseCspSubscriber->onKernelResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 110)
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch(Object, 'kernel.response') (Line: 192)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 180)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
Require webprofiler module and enable it.
Proposed resolution
Change arguments order.
Remaining tasks
Review
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #3
valdispert commentedTested the patch and it fixed the problem!
Comment #4
gappleI will need to re-familiarize myself with Symfony versions and corresponding deprecations - swapping the parameter order may at a minimum also require dropping the module's support for D8 in
*.info.ymlandcomposer.jsonif I recall correctly.Comment #5
gappleMy recollections were correct
- Symfony changed the parameter order in 4.3
- Drupal 8.9 requires Symfony 3.4
- Drupal 9.0 requires Symfony 4.4
However it looks like Webprofiler's 9.0.1 release should also implement the necessary backwards compatibility to work with the original parameter order: https://gitlab.com/drupalspoons/webprofiler/-/issues/45
----
Given that Drupal 8.9 has been out of security support for some time though, and I expect the BC will be removed with Drupal 10's Symfony update, this will still need to be addressed.
Comment #7
gappleSorry, emanuelrighetto, I missed adding your name in the commit message but you are included in the issue credits.
Comment #9
messaddo commentedthe patch not working on Drupal 9.3
Comment #10
gapple@messaddo
??
A complete fix to the issue was already committed and is included in the module's release 1.17 - the patch is not required if your site is up to date.
Comment #11
messaddo commented@gapple
yep but i have the issue when I install webprofiler module