function hook_js_captured_content_alter in JS Callback Handler 7.2
Same name and namespace in other branches
- 8.3 js.api.php \hook_js_captured_content_alter()
Allows modules to alter delivery content with captured (printed) output.
In some rare instances, some code uses "printable" functions (print, print_r, echo, var_dump, etc.) that outputs directly to the browser. This causes issues when data is encoded and compressed in the delivery callback (e.g. gzip compresses the data returned from the callback, but is appended with the printed output as well, thus resulting in a decoding error in the browser).
Instead of just discarding this captured data, this alter hook allows loaded modules (defined by the callback) a chance to alter the delivery content right before it's sent to the browser; in the event that the captured output is useful for some reason.
Parameters
mixed $result: The result value from the callback, passed by reference.
string $captured: The captured output.
1 invocation of hook_js_captured_content_alter()
- js_deliver in ./
js.module - Sends content to the browser via the delivery callback.
File
- ./
js.api.php, line 194 - This file contains no working PHP code; it exists to provide documentation for this module's API.
Code
function hook_js_captured_content_alter(&$result, $captured) {
// Pass the captured output to the JSON array right before delivery.
if (js_delivery_callback() === 'js_deliver_json') {
$result['captured'] = filter_xss_admin($captured);
}
}