Use $this->trigger() instead of Event::trigger() to make it possible to listen to events in Behaviors #1010
Unanswered
kristiansp
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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:
(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:
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.Beta Was this translation helpful? Give feedback.
All reactions