We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Docs for new hooks?

Developer Preview

Brian Litzinger's avatar
Brian Litzinger
693 posts
9 years ago
Brian Litzinger's avatar Brian Litzinger

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

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
9 years ago
Brian Litzinger's avatar Brian Litzinger

After some digging around I found some of the old hooks and was able to get one of the new entry save hooks implemented.

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
9 years ago
Brian Litzinger's avatar Brian Litzinger

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 Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

The new hooks are documented under the Models section at development/extension_hooks/index, hope that helps. I’ll ask Pascal to see if he can help you with the Event service.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
9 years ago
Pascal Kriete's avatar Pascal Kriete

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?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.