function LibraryDiscoveryParser::validateCssLibrary

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::validateCssLibrary()
  2. 10 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::validateCssLibrary()
  3. 11.x core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::validateCssLibrary()

Validates CSS library structure.

Parameters

array $library: The library definition array.

Return value

int Returns based on validity:

  • 0 if the library definition is valid
  • 1 if the library definition has improper nesting
  • 2 if the library definition specifies files as an array
1 call to LibraryDiscoveryParser::validateCssLibrary()
LibraryDiscoveryParser::buildByExtension in core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
Parses and builds up all the libraries information of an extension.

File

core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php, line 527

Class

LibraryDiscoveryParser
Parses library files to get extension data.

Namespace

Drupal\Core\Asset

Code

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 $source => $options) {
            if (!is_array($options)) {
                return 1;
            }
        }
    }
    return 0;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.