EventManagerTrait ================= * Published: 2019-12-21 * Author: Nickolas Burr .. contents:: Table of Contents :local: Description ----------- Magento provides an event-driven subsystem that allows modules to dispatch and observe arbitrary types of events. This is useful for a variety of reasons, such as: * Performing actions upon occurrence of specific events * Receiving important data sent by an event dispatcher * Logging state during time of event dispatch In the example below, we've created a trait called ``EventManagerTrait``. By mixing in the ``EventManagerTrait`` trait, a class can easily dispatch events with data by invoking the ``dispatchEvent`` method. Usage ----- .. code-block:: php eventManager = $eventManager; } /** * @return void */ public function save() { $this->dispatchEvent( 'package_entity_save_before', [ 'entity' => $entity, 'status' => $status, ] ); ... $this->dispatchEvent( 'package_entity_save_after', [ 'entity' => $entity, 'status' => $status, ] ); } } Source ------ .. code-block:: php eventManager ->dispatch($event, $data); } }