0

I would like to some custom things when you are on the create a new website in the admin area page.

This is the exact controller used to render that page:

\Magento\Backend\Controller\Adminhtml\System\Store\NewWebsite::execute

and this is the content of the adminhtml/events.xml file:

<?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="controller_action_postdispatch_system_store_newwebsite">
        <observer name="custom_name"
                  instance="Namespace\Module\Observer\Custom" />
    </event>
</config>

I am looking for the right event name. I tried several variations like:

controller_action_postdispatch_system_store_newwebsite
controller_action_postdispatch_system_store_newWebsite
controller_action_postdispatch_admin_system_store_newwebsite
controller_action_postdispatch_adminhtml_system_store_newWebsite

None of them are working. I am trying to get the full action name. This is from the docs:

controller_action_postdispatch_{full_action_name} – executes after a controller with specific {full_action_name}.

The route defined in the : vendor/magento/module-backend/etc/adminhtml/routes.xml is: admin . See:

<router id="admin">
    <route id="adminhtml" frontName="admin">
        <module name="Magento_Backend" />
    </route>
</router>

Would you please help out, to get the right event name ? Thank you

0

Eventually, I found out a way how to get the right event name, using the controller_action_postdispatch event.

Using the following code, in your observer:

use Magento\Framework\App\RequestInterface;
class MyObserver implements ObserverInterface
{

    private $requestInterface;
     
    public function __construct(
        RequestInterface $requestInterface
    ) {
        $this->requestInterface = $requestInterface;
    }

    public function execute(Observer $observer)
    {
         $fullName = $this->requestInterface->getFullActionName();
         echo $fullName; exit(); // this will the exact `full action name`
    }
0

Try This.

create file etc/events.xml file:

<?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="controller_action_postdispatch_system_store_newwebsite">
        <observer name="custom_name"
                  instance="Namespace\Module\Observer\Custom" />
    </event>
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.