Skip to content

Observers

Global observers list

Observers list

The observers page allows you to view all the observers in your project:

  • Module
  • Event
  • Name
  • Class
  • Scope

Module observers list

In the module detail view, you can see the observers declared by this module.

Module observer creation

You can create a new observer by clicking Generate > Observer button from the module detail view.

Observer create

The module observer creation wizard includes the following features:

  • Autocomplete the list of available events

NOTE

The list of available events is generated from the events.xml files in the project, and is therefore not exhaustive. You can still create an observer for an event that is not in the list, but you will have to manually enter the event name.

The following files are created/updated in app/code/Vendor/Module when you create a new observer:

  • etc/events.xml: created if it does not exist, or updated with the new observer declaration
  • Observer/ObserverName.php: created with the new observer class

NOTE

The observer class name is inferred from the observer name you provide.

Example of a generated observer

PHP class

php
<?php

declare(strict_types=1);

namespace MB\Test\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class Test implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        // Add your code here
    }
}

etc/events.xml

xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="admin_sales_order_address_update">
        <observer name="mb_test_test" instance="MB\Test\Observer\Test" shared="false" disabled="false"/>
    </event>
</config>

Released under the MIT License.
This project is not affiliated with, endorsed by, or sponsored by Adobe Inc. "Magento" and "Adobe Commerce" are trademarks of Adobe Inc.
All trademarks and registered trademarks are the property of their respective owners.