Assert if a library definition is not valid / as expected

Created on 12 June 2016, about 8 years ago
Updated 13 March 2023, over 1 year ago

Problem/Motivation

Library definitions are not adequately validated when they are being parsed, and some commonly made mistakes lead to obscure error messages.

Proposed resolution

  1. Check that if the css or js sections are not empty if they are declared. There is already a check that at least one of those sections should be present, but they can still be left empty. This will catch incorrectly indented YAML such as this example:
    protip:
      css:
      component: # not indented correctly
        css/libraries/protip.min.css: {}
    
  2. Detect if the css or js sections are properly declared as arrays.
    protip:
      js:
        js/mycode.js # this should be an array
    
  3. Detect that the css or js sections are arrays of options, keyed by path.
    protip:
      js:
        - js/mycode.js # the path should be the key, not the value
    
  4. Detect none existant libraries (see #30):
    e.g.
    - core/collapse

Remaining tasks

Review the patch.

User interface changes

None.

API changes

Asserts will be thrown when library definitions are incorrect.

Data model changes

None.

Original report

Hello !

I keep getting this warning in Log everytime i install a new module. Any idea how can i solve this?

Warning: Invalid argument supplied for foreach() in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 133 of /home/r39491rnba/public_html/artosphere.eu/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php).

Thank you !

Feature request
Status

Needs work

Version

10.1

Component
Asset library 

Last updated 1 day ago

No maintainer
Created by

🇷🇴Romania Mircea Shanti

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024