Introduce hook_library_alter() for dynamically altering attached libraries

Created on 17 August 2016, almost 9 years ago
Updated 14 August 2025, about 10 hours ago

Problem/Motivation

There is a particular use case that the current hook_library_info_alter() code does not support. Say module A wants to add a library that depends on the core core/drupal.ajax library. This core library is used in many places, but module A wants its code to always run if that core library is used. One could implement hook_library_info_alter(), and alter the core ajax library definition to depend on module A's library, but then module A's code would run first, which might not be desirable.

This is technically possible using a combination of hook_css_alter(), and hook_js_alter(), but one must then manually specify every js and css file, and also parse through fully-qualified asset paths to determine which libraries are included.

Proposed resolution

Add hook_library_alter() for modules and themes to have the opportunity to add additional libraries.

Remaining tasks

User interface changes

API changes

Addition of a new hook.

Data model changes

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

asset library system

Created by

πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024