Error: Argument #1 ($event) must be of type object

Created on 17 July 2023, over 1 year ago
Updated 22 June 2024, 5 months ago

Problem/Motivation

I see a warning message whe a user flagged the article.

Oops, something went wrong. Check your browser's developer console for more details.

Here's the issue reported when I checked logs.

TypeError: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /var/www/html/yopen/web/modules/contrib/rules_flag/rules_flag.module on line 32 in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 89 of /var/www/html/mysite/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).

Any idea, please ?

๐Ÿ’ฌ Support request
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jaydenpearly
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jaydenpearly
  • ๐Ÿ‡ช๐Ÿ‡ธSpain webtematica

    Hi, i confirm the same problem in Drupal 10 with PHP 8.1. and the dev version of the module.
    It needs to push twice to change the state of the flag.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aharown07

    I am seeing this error also since moving from Drupal 9.5 to 10.

    My flags and rules were working perfectly in 9.5 but now one flag has to be clicked twice, and another goes to an error page "The website encountered an unexpected error. Please try again later." Then clicking the flag appears to not execute the rule.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !10fixed โ†’ (Open) created by chetan 11
  • Status changed to Needs review 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    Hi,
    I have fixed the above error "Error: Argument #1 ($event) must be of type object", please check the solution in raised MR.
    Thanks.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tawellman

    I am getting the same thing. Is there a patch I am missing?

    The website encountered an unexpected error. Try again later.
    
    TypeError: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /home/sewardsdevel9/sewards10/web/modules/contrib/rules_flag/rules_flag.module on line 45 in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 89 of core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).
    
    rules_flag_flagging_delete()
    call_user_func_array() (Line: 409)
    Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 388)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 416)
    Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 215)
    Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
    Drupal\Core\Entity\ContentEntityStorageBase->invokeHook() (Line: 462)
    Drupal\Core\Entity\EntityStorageBase->delete() (Line: 753)
    Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (Line: 360)
    Drupal\Core\Entity\EntityBase->delete() (Line: 344)
    Drupal\flag\FlagService->unflag() (Line: 116)
    Drupal\flag\Controller\ActionLinkNoJsController->unflag()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
    Drupal\ban\BanMiddleware->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    

    I am on:

    • Drupal 10.2.2
    • Rules 8.x-3.0-alpha8+2-dev
    • Rules Flag 1.0.2+1-dev

    I install the Rules flag module and try to flag an ECK entity and get the above WSOD error. Refresh the screen and entity displays fine and is flagged like it should be. When I unflag it, error shows back up. NO rules written yet. Example Rules have also been disabled.

    Uninstall the module and flagging works a designed.

    I am migrating a site that relied a lot on Rules and Flags. Is there any chance someone can help me find a solution?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tawellman

    I think I figured it out. Looks like maybe the arguments in lines 23, 32, and 45 are in the wrong order. Changed them to the following and things look to be working.

    23    $event_dispatcher->dispatch($event, UserFlaggedEvent::EVENT_NAME);
    
    32  $event_dispatcher->dispatch($event, "rules_flag_entity_flagged:$entity_type");
    
    45  $event_dispatcher->dispatch($event, "rules_flag_entity_unflagged:$entity_type");
    

    I know just enough to be a little useful sometimes. Never wrote a patch, so if someone could handle that end, that would be cool!

    Hope this helps!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aharown07

    tawellman's edits to rules_flag.module (for me ver 1.0.3) are also working on my sites.

    I also don't know how to roll patches the git way. I see instructions here โ†’ and here โ†’ , but I currently manage a single public website and one dev version... so it has not made sense to learn Git just for that.
    ... likewise for interdiff โ†’ and drupalorg-cli.

    But here's an old fashioned diff patch.

  • ๐Ÿ‡จ๐Ÿ‡ณChina drupalfan79

    the rout cause is the change in Drupal core 9.1 https://www.drupal.org/project/drupal/issues/3055194 โ†’

  • Status changed to Fixed 7 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024