1

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:

modules
   -telephone_alter
theme:
   contrib:
      -bootstrap
   custom:
      -bootstrap_subtheme

Here is bootstrap_subtheme.libraries.yml:

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

1 Answer 1

1

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.)

3
  • 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
    Commented Aug 11, 2020 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
    Commented Aug 11, 2020 at 18:01
  • @Hudri @beltouche it was the simple hyphen in global-styling that was my mistake Commented Aug 11, 2020 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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