Skip to content

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

@kristiansp

Description

@kristiansp

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions