Trying to attach js by means of #attached by means of hook_page_alter (see https://drupal.stackexchange.com/questions/171918/how-to-add-javascript-with-attached-and-hook-page-alter), I found that the following code
function MODULE_page_alter(&$page) {
$my_path = drupal_get_path('module', 'MODULE' );
$page ['content']['#attached']['js'][] = array(
'js' => array(
'type'=>'file',
'data' => $my_path . '/module_test.js'),
);
}
works properly - it attaches the file - while
function MODULE_page_alter(&$page) {
$my_path = drupal_get_path('module', 'MODULE' );
$page ['#attached']['js'][] = array(
'js' => array(
'type'=>'file',
'data' => $my_path . '/module_test.js'),
);
}
does not. Why is it so?
dpm()
indrupal_render_page()
to check if$page['#attached']['js']
is still there afterdrupal_alter('page', $page)
. And if not, you coulddpm(module_implements('page_alter'))
and find out which module implementation is removing the js.