- Issue created by @m.stenta
- πΊπΈUnited States m.stenta
I worked around this issue by explicitly attaching the library in my build array:
$form['progress'] = [ '#theme' => 'progress_bar', '#label' => $this->steps()[$step]['label'], '#percent' => $this->steps()[$step]['progress'], '#message' => $this->steps()[$step]['message'], ]; // Fix issue with progress library not being added in some contexts (eg: // the intake quick form for anonymous users). $form['progress']['#attached']['library'][] = 'core/drupal.progress';
- @mstenta opened merge request.
- πΊπΈUnited States m.stenta
I opened a merge request that fixes this issue.
I assume this will need tests, but marking as "Needs review" to get thoughts from the maintainers. Is this the right way to solve this?
- πΊπΈUnited States smustgrave
If we can help it think we don't want to go the twig route as this fix won't appear on custom or contrib themes without updating all templates. If it's missing should attach to the render array if possible.
- πΊπΈUnited States m.stenta
@smustgrave I wondered that too, before eventually found that it was already being added to various core twig templates (although it seems like the Claro one is just broken, because it references
claro/classy.progress
which does not exist):- https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...
- https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...
- https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...
Although in all of those cases, it is adding a more specific library that extends
core/drupal.progress
(vialibraries-extend
/ https://www.drupal.org/node/2497313 β )Notably it is NOT added to the other two twig templates:
- https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...
- https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...
So you're probably right - it should be attached to the render array at a lower level.
The
progress_bar
theme element is defined here: https://git.drupalcode.org/project/drupal/-/blob/e09b671ee2ad91b55e4b68f...Is it possible to attach libraries there? I don't see any other examples of that in the file, nor in
hook_theme()
documentation generally (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...).Would we need to add a
template_preprocess_progress_bar
?This is why I went the route of adding it to the twig templates - to avoid that. But maybe it's the best route?
- πΊπΈUnited States smustgrave
If the claro one doesn't exist then yea that would have to be fixed at the twig level. I would definitely try template_preprocess_progress_bar