October CMS. Backend Widgets. Events. How to listen/catch the onAddItem?

177 views Asked by At

How I can listen/catch the data-request="formVideo::onAddItem" in a Plugin.php's boot() method?

In a backend, there is a Repeater widget and it has a button ( https://i.stack.imgur.com/546YC.png ). I need to catch the event of this button in a boot() method of a Plugin.php.

1

There are 1 answers

0
hamid imomov On

Here ( https://octobercms.com/forum/post/events-how-to-listencatch-the-onadditem ), I received the solution: https://octobercms.com/docs/api/backend/ajax/beforerunhandler

Event::listen('backend.ajax.beforeRunHandler', function ((\Backend\Classes\Controller) $controller, (string) $handler) {
    if (strpos($handler, '::')) {
        list($componentAlias, $handlerName) = explode('::', $handler);
        if ($componentAlias === $this->getBackendWidgetAlias()) {
            return $this->backendControllerProxy->runAjaxHandler($handler);
        }
    }
});