/**
* Wraps content for compability with legacy Elgg ajax calls
*
* @param string $content Response content
* @param string $forward_url Forward URL
* @return string
*/
public function wrapLegacyAjaxResponse($content = '', $forward_url = REFERRER)
{
$content = $this->stringify($content);
if ($forward_url === REFERRER) {
$forward_url = $this->request->headers->get('Referer');
}
// always pass the full structure to avoid boilerplate JS code.
$params = ['output' => '', 'status' => 0, 'system_messages' => ['error' => [], 'success' => []], 'current_url' => current_page_url(), 'forward_url' => elgg_normalize_url($forward_url)];
$params['output'] = $this->ajax->decodeJson($content);
// Grab any system messages so we can inject them via ajax too
$system_messages = _elgg_services()->systemMessages->dumpRegister();
if (isset($system_messages['success'])) {
$params['system_messages']['success'] = $system_messages['success'];
}
if (isset($system_messages['error'])) {
$params['system_messages']['error'] = $system_messages['error'];
$params['status'] = -1;
}
$response_type = $this->parseContext();
list($service, $name) = explode(':', $response_type);
$context = [$service => $name];
$params = $this->hooks->trigger('output', 'ajax', $context, $params);
return $this->stringify($params);
}