I have begun trying to port a small, simple module that I maintain to Drupal 8.
It was originally written (not by me) in Drupal 6 and used
hook_init() in combination with
drupal_add_js() to attach its scripts to every page.
drupal_add_js() have been deprecated in Drupal 8. I only really need to attach scripts to pages that have a taxonomy term reference widget (and in fact much of my logic has already been moved into a
hook_field_widget_taxonomy_autocomplete_form_alter().) Scripts are now added via
#attached which I understand, but since I don't have the
$form array or object in
hook_field_widget_taxonomy_autocomplete_form_alter() I'm not sure where to add the
I'm also not clear if
#attached is used instead of or in addition to a *.libraries.yml file. Does every single module with its own script.js need to declare a *.libraries.yml file?
How do I attach my custom js file to every page with a taxonomy term reference widget in Drupal 8?