From 1032fd0cc1eedbf602743ee0b192ef3b201f4b7d Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sat, 18 Aug 2018 09:05:38 -0600 Subject: [PATCH] Added more inline API event docs: Added docs for: cms.component.beforeRunAjaxHandler cms.component.runAjaxHandler Improved docs for: cms.ajax.beforeRunHandler --- modules/cms/classes/ComponentBase.php | 54 +++++++++++++++++++++++++-- modules/cms/classes/Controller.php | 45 +++++++++++++--------- 2 files changed, 78 insertions(+), 21 deletions(-) diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 9546cd4c0..7a12a1c3c 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -153,8 +153,34 @@ abstract class ComponentBase extends Extendable */ public function runAjaxHandler($handler) { - /* - * Extensibility + /** + * @event cms.component.beforeRunAjaxHandler + * Provides an opportunity to modify an AJAX request to a component before it is processed by the component + * + * The parameter provided is `$handler` (the requested AJAX handler to be run) + * + * Example usage (forwards AJAX handlers to a backend widget): + * + * Event::listen('cms.component.beforeRunAjaxHandler', function((\Cms\Classes\ComponentBase) $component, (string) $handler) { + * if (strpos($handler, '::')) { + * list($componentAlias, $handlerName) = explode('::', $handler); + * if ($componentAlias === $this->getBackendWidgetAlias()) { + * return $this->backendControllerProxy->runAjaxHandler($handler); + * } + * } + * }); + * + * Or + * + * $this->controller->bindEvent('component.beforeRunAjaxHandler', function ((string) $handler) { + * if (strpos($handler, '::')) { + * list($componentAlias, $handlerName) = explode('::', $handler); + * if ($componentAlias === $this->getBackendWidgetAlias()) { + * return $this->backendControllerProxy->runAjaxHandler($handler); + * } + * } + * }); + * */ if ($event = $this->fireSystemEvent('cms.component.beforeRunAjaxHandler', [$handler])) { return $event; @@ -162,8 +188,28 @@ abstract class ComponentBase extends Extendable $result = $this->$handler(); - /* - * Extensibility + /** + * @event cms.component.runAjaxHandler + * Provides an opportunity to modify an AJAX request to a component after it is processed by the component + * + * The parameters provided are `$handler` (the requested AJAX handler to be run) and `$result` (the result of the component processing the request) + * + * Example usage (Logs requests and their response): + * + * Event::listen('cms.component.beforeRunHandler', function((\Cms\Classes\ComponentBase) $component, (string) $handler, (mixed) $result) { + * if (in_array($handler, $interceptHandlers)) { + * return 'request has been intercepted, original response: ' . json_encode($result); + * } + * }); + * + * Or + * + * $this->controller->bindEvent('componenet.beforeRunAjaxHandler', function ((string) $handler, (mixed) $result) { + * if (in_array($handler, $interceptHandlers)) { + * return 'request has been intercepted, original response: ' . json_encode($result); + * } + * }); + * */ if ($event = $this->fireSystemEvent('cms.component.runAjaxHandler', [$handler, $result])) { return $event; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 5b5c3d32a..28e3679da 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -688,23 +688,34 @@ class Controller protected function runAjaxHandler($handler) { /** - * @event cms.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): - * - * $this->controller->bindEvent('ajax.beforeRunHandler', function ($handler) { - * if (strpos($handler, '::')) { - * list($componentAlias, $handlerName) = explode('::', $handler); - * if ($componentAlias === $this->getBackendWidgetAlias()) { - * return $this->backendControllerProxy->runAjaxHandler($handler); - * } - * } - * }); - * - */ + * @event cms.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('cms.ajax.beforeRunHandler', function((\Cms\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('cms.ajax.beforeRunHandler', [$handler])) { return $event; }