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

CommentFileSizeAuthor
eventdispatcher.patch616 bytesemanuelrighetto

Issue fork csp-3314249

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

emanuelrighetto created an issue. See original summary.

valdispert’s picture

Status: Active » Reviewed & tested by the community

Tested the patch and it fixed the problem!

gapple’s picture

I 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.yml and composer.json if I recall correctly.

gapple’s picture

My 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.

  • gapple committed b0f6be1 on 8.x-1.x
    Issue #3314249 by gapple, Valdispert: Update argument order when calling...
gapple’s picture

Title: Make eventDispatcher compatible with "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" » Update argument order when calling EventDispatcher::dispatch()
Status: Reviewed & tested by the community » Fixed

Sorry, emanuelrighetto, I missed adding your name in the commit message but you are included in the issue credits.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

messaddo’s picture

the patch not working on Drupal 9.3

gapple’s picture

@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.

messaddo’s picture

@gapple

yep but i have the issue when I install webprofiler module