Maybe I’m not looking in the right place, but I don’t see anything on what has been updated in 3.1 for the hooks. I’m seeing the forwardEventsToHooks() method, which looks like I should be subscribing to events instead of adding rows to the exp_extensions table? Is there some place else I should be looking for direction on the best approach for EE3?
I see this page in the docs, but it looks like all the old hooks. Are these still the preferred approach? /development/extension_hooks/index.html
The event documentation seems to be lacking as well. E.g. it shows how to create a subscriber and publisher, but it doesn’t really provide a real use case. If I want to subscribe to a native event, where do I register the subscriber? The best I could figure is in the ext constructor. Am I approaching this incorrectly?
public function __construct()
{
$emitter = ee('Event');
$emitter->subscribe(new MySubscriber());
}
Kevin is correct. The old hook approach is still the preferred one for those times where you want to subscribe to one of the core events (aside from model-to-model interaction, where a relationship is the way to go). We automatically connect the model events to the old hooks using that method you found. The event service could be used to re-implement extensions for roughly the same functionality, but we haven’t done that yet.
So I suppose some of the confusion comes from the fact that there is no global singleton event bus. If you’re trying to create one that is global to your add-on, this should work:
// addon.setup.php
'services.singletons' => array(
'Event' => function($addon) {
return $add->make('ee:Event');
}
)
// usage:
ee('myaddon:Event')
Can you elaborate on what you’re trying to do?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.