backend.ajax.beforeRunHandler

Triggered in Backend\Classes\Controller.

Provides an opportunity to modify an AJAX request

The parameter provided is $handler (the requested AJAX handler to be run)

Example usage (forwards AJAX handlers to a backend widget):

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

Or

$this->controller->bindEvent('ajax.beforeRunHandler', function ((string) $handler) {
    if (strpos($handler, '::')) {
        [$componentAlias, $handlerName] = explode('::', $handler);
        if ($componentAlias === $this->getBackendWidgetAlias()) {
            return $this->backendControllerProxy->runAjaxHandler($handler);
        }
    }
});