I am trying to create afterSave plugin for my admin form save action controller of my custom module. The purpose of this is to save some data into second table once all data completely save in first table.

Here is my di.xml file code :

<type name="Namespace\Module\Controller\Adminhtml\Options\Save">
    <plugin name="save_option_label" type="Namespace\Module\Plugin\OptionlabelSave" sortOrder="1" />
</type>

I have also created OptionlabelSave.php file inside \Plugin\ directory.

Here is the code :

<?php

namespace Namespace\Module\Plugin;

/**
 * Class OptionlabelSave
 * @package Namespace\Module\Plugin
 */
class OptionlabelSave
{
    public function afterSave(Namespace\Module\Controller\Adminhtml\Options\Save $subject, $result) {
        echo 'test save'; exit;

        return $result;
    }
}

However, when I click on save button in admin edit form I am not getting 'test save' printed on my screen. Am I missing anything here?

Please help. That would be highly appreciated.

Thanks,

有帮助吗?

解决方案

I have found the solution myself. Earlier, I have used afterSave() method inside plugin file. Instead, we need to use either afterExecute() or aroundExecute() depending upon the type of requirement.

That's it!

Thanks,

许可以下: CC-BY-SA归因
scroll top