O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Events and observers

Magento implements the observer pattern through \Magento\Framework\Event\ManagerInterface. In app/etc/di.xml, there is a preference for ManagerInterface that points to the Magento\Framework\Event\Manager\Proxy class type. The Proxy class further extends the \Magento\Framework\Event\Manager class that implements the actual event dispatch method.

Events are dispatched by calling a dispatch method on the instance of the Event\Manager class and passing the name and some data, which is optional, to it. Here's an example of a Magento core event:

$this->eventManager->dispatch(
    'customer_customer_authenticated',
    ['model' => $this->getFullCustomerObject($customer), 'password' => $password]
);

The $this->eventManager is an instance of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required