I'm returning a form with #ajax functionality in an Ajax response. The form is properly loaded into the page, however it is not #ajaxified, as the drupalSettings are not being returned. In D7, we could generate the JS settings AKA Drupal.settings using the following code:
$scripts = drupal_add_js();
if (!empty($scripts['settings']))
{
$settings = '<script type="text/javascript">jQuery.extend(Drupal.settings, ';
$settings .= drupal_json_encode(call_user_func_array('array_merge_recursive', $scripts['settings']['data']));
$settings .= ');</script>';
}
I'm trying to find the D8 equivalent of this code, but not having much success. At the moment I'm returning a JsonResponse from my ajax callback, but I'm thinking I probably need to return an AjaxResponse. What I can't figure out is how to pass my generated form to the AjaxResponse, in order for it to return the settings along with the HTML for the form.