Didn't handle css group correctly

Created on 17 April 2024, 8 months ago
Updated 25 July 2024, 5 months ago

Problem/Motivation

When user select css group, css file didn't get the right group number in options.
Example:
css group: theme
the group number should be set to 100 for this css.

Reference 1: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/includes/comm...

/**
 * The default aggregation group for theme CSS files added to the page.
 */
const CSS_AGGREGATE_THEME = 100;

Reference 2:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

    $default_options = [
      'type' => 'file',
      'group' => CSS_AGGREGATE_DEFAULT,
      'weight' => 0,
      'media' => 'all',
      'preprocess' => TRUE,
    ];

    foreach ($libraries_to_load as $library) {
      [$extension, $name] = explode('/', $library, 2);
      $definition = $this->libraryDiscovery->getLibraryByName($extension, $name);
      if (isset($definition['css'])) {
        foreach ($definition['css'] as $options) {
          $options += $default_options;
          // Copy the asset library license information to each file.
          $options['license'] = $definition['license'];

          // Files with a query string cannot be preprocessed.
          if ($options['type'] === 'file' && $options['preprocess'] && str_contains($options['data'], '?')) {
            $options['preprocess'] = FALSE;
          }

          // Always add a tiny value to the weight, to conserve the insertion
          // order.
          $options['weight'] += count($css) / 30000;

          // CSS files are being keyed by the full path.
          $css[$options['data']] = $options;
        }
      }
    }

Steps to reproduce

Cerate a new library and add a css whose group be setted to "Theme" and give a weight:10, It should be loaded after theme css with no wight.

Proposed resolution

Handle group number here like drupal core did.
https://git.drupalcode.org/project/library_manager/-/blob/2.0.x/library_...

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇳China lawxen

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

Comments & Activities

Production build 0.71.5 2024