Passing data from PHP to javascript variable available to all pages in Drupal 8
Most of us pass data from PHP to javascript variable available to all pages in Drupal 7 is by:
/**
* Implements hook_init()
*/
function mymodule_init() {
$computed_data = mymodule_get_data();
drupal_add_js(array('mymodule_computed_data' => $computed_data), 'setting');
}
We can access this data in javascript by: