问题描述
如何在 Plugin.PHP 的 boot() 方法中监听/捕获 data-request="formVideo::onAddItem"
?
在后端,有一个 Repeater 小部件,它有一个按钮 ( https://i.imgur.com/gORjH26.png )。我需要在 Plugin.PHP 的 boot() 方法中捕获此按钮的事件。
解决方法
在这里(https://octobercms.com/forum/post/events-how-to-listencatch-the-onadditem),我收到了解决方案: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);
}
}
});