moved_files key in core.libraries.yml has unexpected structure

Created on 21 May 2024, 4 months ago
Updated 30 May 2024, 3 months ago

Problem/Motivation

In Drupal 10.3, there is a new yaml key in *.libraries.yml, moved_files to indicate a file has moved. Also in Drupal 10.3, a bunch of core files have moved and this key is set in core.libraries.yml.

LibraryDiscoveryParser.php::applyLibrariesMovedOverrides() and supporting test cases are expecting the key values to be arrays, but the values set in the updated core.libraries.yml file are coded as yaml strings. This generates an error:

Fatal error: Uncaught TypeError: array_key_first(): Argument #1 ($array) must be of type array, string given in /var/www/html/docroot/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php on line 455

e.g. for drupal.ajax, the key under 'drupal.ajax/moved_files/system/base/css/component' has a value that is a string:

drupal.ajax:
  version: VERSION
  js:
    misc/ajax.js: {}
  css:
    component:
      misc/components/ajax-progress.module.css: { weight: -10 }
  moved_files:
    system/base:
      deprecation_version: 10.3.0
      removed_version: 11.0.0
      deprecation_link: https://www.drupal.org/node/3432346
      css:
        component:
          css/components/ajax-progress.module.css: misc/components/ajax-progress.module.css

LibraryDiscoveryParser is assuming that a yml mapping has been converted to a PHP array.

Steps to reproduce

1. Install latest Drupal 10.3.0-beta1 or greater.
2. Install a project that overrides libraries that were moved in πŸ“Œ Move system/base component CSS to respective libraries where they exist Fixed , e.g. drupal/stable
3. Load a page that uses the overridden library. e.g. enable and set the contributed Stable theme as the default theme.

drush cr can trigger the error also.

Proposed resolution

Allow keys for overridden libraries to be strings OR arrays.

1. Check to see if the value is an array before passing it to array_key_exists().
2. Add a test case in which the key value of the overridden library is a string

It looks like it would be possible to code the yml as a sequence/array instead of a mapping, but I don't know enough about the asset system to say if that would ever come up. Should we check for that case also?

Alternatively, update the yaml structures in core.libraries.yml to make these keys into yaml mappings instead of strings.

  • drupal.ajax
  • drupal.autocomplete
  • drupal.progress
  • drupal.tabledrag
πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
Asset libraryΒ  β†’

Last updated 1 day ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States calebtr

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

Comments & Activities

Production build 0.71.5 2024