I have a subtheme called bootstrap_subtheme. It has a library called global-styling. I created a custom module called telephone_alter. In telephone_alter.module, I have the following:

function telephone_alter_form_user_form_alter(&$form){
  $form['#attached']['library'][] = 'bootstrap_subtheme/global_styling';

it does not load the bootstrap_subtheme library stylesheet. I do dump($form) and get the following:

  "#attached" => array:1 [▼
    "placeholders" => array:1 [▼
      "form_action_p_pvdeGsVG5zNF_XLGPTvYSKCf43t8qZYSwcfZl2uzM" => array:1 [▼
        "#lazy_builder" => array:2 [▶]

seems like the attachment isn't even grabbing it. Yes I am using the right form alter according to the api: hook_form_FORM_ID_alter() and my ID is user_form . It does fire off, if I attach css from within my module's folder, but not my subtheme. Any help would be great! Thank you.

One more note:

my root dir is as follows:


Here is bootstrap_subtheme.libraries.yml:

    js/popper.min.js: {}
    js/bootstrap.min.js: {}
    js/global.js: {}
      css/style.css: {}
    - core/jquery
    - core/drupal
  • Show us your bootstrap_subtheme.libraries.yml file too – beltouche Aug 11 '20 at 2:43
  • @beltouche editted the post to include bootstrap_subtheme.libraries.yml – Armando Silva Aug 11 '20 at 5:59

Based on that structure, you're referencing the library incorrectly. It should be $form['#attached']['library'][] = 'bootstrap_subtheme/bootstrap_subtheme.global-styling';

As noted in a comment below, the duplicate use of the theme name may not be necessary, and $form['#attached']['library'][] = 'bootstrap_subtheme/global-styling'; should work according to the docs. (Note the use of a dash, matching the library name versus an underscore in your code.)

  • 1
    This is not true, the syntax used in the question is correct. It is simply module_name/library_name. No need to repeat the module name after the slash. – Hudri Aug 11 '20 at 17:11
  • Interesting. Every case I've had in my experience, I have the module name there, although I see in the docs, there's no requirement for it. It just be the author's use of an underscore versus a hyphen then. – beltouche Aug 11 '20 at 18:01
  • @Hudri @beltouche it was the simple hyphen in global-styling that was my mistake – Armando Silva Aug 11 '20 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.