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

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

21kPiyush created an issue. See original summary.

sahil.goyal made their first commit to this issue’s fork.

sahil.goyal’s picture

Issue summary: View changes
Status: Active » Needs review

Hi @21kPiyush Thanx for the MR, MR!8 is no doubt resolving the issue by adding the is_object condition, you ensure that the dispatch method is only called when the $event variable is indeed an object, But we can opt other approach as Symfony5/6 enforce the new syntax and needed for D10 Compatibility as well, So i created a MR !9 by updating the argument as needed and it also resolving the issue and functionally works as expected, Please Review.

Also Updating the Issue Summary for steps to reproduce.

keshav.k made their first commit to this issue’s fork.

keshavv’s picture

@sahil.goyal
The changes that you added in MR ! 9 are Good, But some of them are already there in the 3. x branch.
It will be good if we contribute to the same MR instead of creating a new one. It will confuse the maintainer.

Here the only problem is, We need to swap the arguments in the dispatch method call.
We need an object argument first in the dispatch method according to Drupal 10.

I have updated MR ! 8 with that.
We can process it with MR ! 8

Please review.
Thank you!

rcodina’s picture

@keshav.k is right, branch 2.x will remain intact. Only branch 3.x will get the MR because is the only one compatible with Drupal 10. I added the change record link at the end of the main description.

rcodina’s picture

I'm sorry @keshav.k, I approved the MR but it seems that there is no attribution for you. Thanks for fixing the original MR.

rcodina’s picture

Status: Needs review » Fixed
rcodina’s picture

@keshav.k I try to compensate with the commit which updates the CHANGELOG about this issue.

  • rcodina committed fe44f227 on 3.x authored by keshav.k
    Issue #3374653 by 21kPiyush, keshav.k, rcodina: ($event) must be of type...
rcodina’s picture

Thanks @21kPiyush and @keshav.k

Status: Fixed » Closed (fixed)

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