Library CSS definition should not fail is no CSS files defined

Created on 12 October 2024, 10 months ago

Problem/Motivation

If a library definition includes an empty "css" -%:gt; "component" structure, the following error is thrown:

CSS files should be specified as key/value pairs, where the values are configuration options. See https://www.drupal.org/node/2274843 .

Steps to reproduce

Create a modulename.libraries.yml file with a library definition that includes an incomplete "css" "component" section:

mylibrary:
  css:
    component:

What should happen:
* Nothing, the site should continue working.

What actually happens:
* The site fails.

Proposed resolution

The codebase only fails if the library's css -> component structure contains an invalid structure, it doesn't fail if the structure is simply empty.

Remaining tasks

TBD

User interface changes

TBD

Introduced terminology

n/a

API changes

TBD

Data model changes

n/a

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

theme system

Created by

🇺🇸United States damienmckenna NH, USA

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

Merge Requests

Comments & Activities

  • Issue created by @damienmckenna
  • 🇺🇸United States damienmckenna NH, USA

    What I'm thinking is something like this:

    diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
    index 78097760f4..44aa8f1c47 100644
    --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
    +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
    @@ -654,16 +654,16 @@ protected function resolveThemeAssetPath($theme_path, $overriding_asset) {
        *     - 2 if the library definition specifies files as an array
        */
       public static function validateCssLibrary($library) {
    -    $categories = [];
         // Verify options first and return early if invalid.
         foreach ($library as $category => $files) {
           if (!is_array($files)) {
             return 2;
           }
    -      $categories[] = $category;
    -      foreach ($files as $options) {
    -        if (!is_array($options)) {
    -          return 1;
    +      if (!is_null($files)) {
    +        foreach ($files as $options) {
    +          if (!is_array($options)) {
    +            return 1;
    +          }
             }
           }
         }
    
  • 🇺🇸United States damienmckenna NH, USA
  • Pipeline finished with Failed
    10 months ago
    Total: 223s
    #308056
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • 🇮🇳India mrinalini9 New Delhi

    Fixed pipeline issues (PhpCodingStandard + Javascript linting) and have updated the MR, please review it.

    Thanks!

  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • 🇺🇸United States smustgrave

    test-only feature passes when it should be failing so test coverage needs to be expanded.

Production build 0.71.5 2024