Add library only if needed

Created on 2 January 2025, 5 months ago

Problem/Motivation

https://git.drupalcode.org/project/navigation_extra_tools/-/blob/1.1.x/n...

/**
 * Implements hook_page_attachments().
 */
function navigation_extra_tools_page_attachments(&$variables) {
  $variables['#attached']['library'][] = 'navigation_extra_tools/icon';
}

The module loads a library which depends on navigation/internal.navigation, which is marked as internal by Core, and there is no check if the navigation toolbar is present.

So, currently it provokes the following bug ๐Ÿ› admin-toolbar-wrapper: Uncaught TypeError: doc.querySelector(...) is null Active .

Steps to reproduce

Enable navigation_extra_tools on a website, D10.3+ or D11.
Go on the website as anonymous user, see that the library is loaded.

Proposed resolution

Even if a module can't extend a library with its .info.yml like a theme, do the equivalent with a hook_library_alter instead of with a hook_page_attachements.

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance Grimreaper France ๐Ÿ‡ซ๐Ÿ‡ท

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024