Registering and Executing Your Own Events

If you're building an add-on that other developers might want to extend, it might help you to create custom events within your add-on. For example, let's say this code is in an eCommerce add-on, and is executed when a product is added.

Custom Event Objects

Notice how we use the Symfony\Component\EventDispatcher\GenericEvent object in this example? That's because it's a simple event object for us to use. It lets us pass arbitrary variables in using the getArgument() and setArgument() methods. But if we want something more strongly typed like our Concrete\Core\User\Event\UserInfoWithPassword class, we simply need to instantiate it, and make sure it extends the Symfony\Component\EventDispatcher\Event abstract event: