You are here

public static function LibraryDiscoveryParser::validateCssLibrary in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::validateCssLibrary()
  2. 9 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

File

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

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