($event) must be of type object

Created on 14 July 2023, over 1 year ago
Updated 18 July 2023, over 1 year ago

Problem/Motivation

I am using Drupal 10 and role expire module 3.0 and i got this error when cron run

TypeError: Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /public_html/web/modules/contrib/role_expire/role_expire.module on line 373

I fixed for now by adding the condition

if (is_object($event)) {
$event_dispatcher->dispatch(RoleExpiresEvent::EVENT_NAME, $event);
\Drupal::logger('role_expire')->notice(t('Removed role @role from user @account.', ['@role' => $expire->rid, '@account' => $account->id()]));
}

if this is correct or any other way to do so??

Steps to reproduce

  1. Install the Module on D10
  2. Create a new User having role Content editor
  3. provide near future Administrator role expiration date/time
  4. Create a Node from newly Content editor user
  5. Wait till the time role gets expired and run cron

CR https://www.drupal.org/node/3159012 โ†’

๐Ÿ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia 21kPiyush

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

Comments & Activities

Production build 0.71.5 2024