The hook_library_info_alter are merging libraries from different assets

Created on 30 January 2025, 23 days ago

Problem/motivation

The url_embed_library_info_alter hook merges all libraries from different assets and adding all them to the CSS asset. However, in my scenario, I need to add a library to the dependencies asset.

Since my module is executed first, the url_embed_library_info_alter hook modifies the library, causing it to stop working.

Steps to reproduce

  1. Create a hook in a module with weight higher then URL Embed
  2. Create a library with CSS file
  3. Add this library to CKEditor using url_embed_library_info_alter hook, check code below
  4. Check the URL will move the library to CSS key array
function my_module_library_info_alter(array &$libraries, string $extension): void {
  // Load components styles for CKEditor5 styles.
  if ($extension === 'ckeditor5' && isset($libraries['internal.drupal.ckeditor5.stylesheets'])) {
    $libraries['internal.drupal.ckeditor5.stylesheets']['dependencies'][] = 'social_editor/ckeditor5_fullscreen';
  }
}

Proposed resolution

The hook should merge only libraries from css asset and not for others.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil viniciusrp

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