Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $this->trigger() instead of Event::trigger() to make it possible to listen to events in Behaviors #730

Closed
kristiansp opened this issue Aug 6, 2020 · 0 comments · May be fixed by #737

Comments

@kristiansp
Copy link
Contributor

Description

I make extensive use of Feed Me events, and decided to move them to a behavior, as is also suggested in the Yii 2.0 documentation.

The problem is that some events are not picked up, and I've narrowed it down to events that are triggered in this way:

Event::trigger(static::class, self::EVENT_AFTER_PARSE_FEED, $event);

(from /services/DataTypes.php)

If the event is triggered from the object itself (like other Feed Me events are), then the Behavior will pick it up, for instance like this:

$this->trigger(self::EVENT_AFTER_PARSE_FEED, $event);

I'm guessing the issue here is that since the Behavior is attached dynamically, it's not registered when the class is added statically (btw, self::class gives the same result).

Unless there's any specific reason to trigger events with Event::trigger() instead of $this->trigger(), I would suggest to change them everywhere, so that events can be handled in behaviors consistently.

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants