From 2c82b0506247ddff595f38fd8dd39845832b466a Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sun, 14 Oct 2018 10:32:47 -0600 Subject: [PATCH] Added backend.ajax.beforeRunHandler event --- modules/backend/classes/Controller.php | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 4ce71dfca..fa7b12279 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -498,6 +498,39 @@ class Controller extends Extendable */ protected function runAjaxHandler($handler) { + /** + * @event backend.ajax.beforeRunHandler + * 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, '::')) { + * list($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, '::')) { + * list($componentAlias, $handlerName) = explode('::', $handler); + * if ($componentAlias === $this->getBackendWidgetAlias()) { + * return $this->backendControllerProxy->runAjaxHandler($handler); + * } + * } + * }); + * + */ + if ($event = $this->fireSystemEvent('backend.ajax.beforeRunHandler', [$handler])) { + return $event; + } + /* * Process Widget handler */