You are here

function libraries_traverse_library in Libraries API 8.3

Same name and namespace in other branches
  1. 7.3 libraries.module \libraries_traverse_library()
  2. 7.2 libraries.module \libraries_traverse_library()

Helper function to apply a callback to all parts of a library.

Because library declarations can include variants and versions, and those version declarations can in turn include variants, modifying e.g. the 'files' property everywhere it is declared can be quite cumbersome, in which case this helper function is useful.

Parameters

$library: An array of library information, passed by reference.

$callback: A string containing the callback to apply to all parts of a library.

Deprecated

Will be removed before a stable Drupal 8 release. Please use the new library load and managment concepts described at: https://www.drupal.org/node/2170763

1 call to libraries_traverse_library()
libraries_invoke in ./libraries.module
Invokes library callbacks.

File

./libraries.module, line 236
External library handling for Drupal modules.

Code

function libraries_traverse_library(&$library, $callback) {

  // Always apply the callback to the top-level library.
  $callback($library, NULL, NULL);

  // Apply the callback to versions.
  if (isset($library['versions'])) {
    foreach ($library['versions'] as $version_string => &$version) {
      $callback($version, $version_string, NULL);

      // Versions can include variants as well.
      if (isset($version['variants'])) {
        foreach ($version['variants'] as $version_variant_name => &$version_variant) {
          $callback($version_variant, $version_string, $version_variant_name);
        }
      }
    }
  }

  // Apply the callback to variants.
  if (isset($library['variants'])) {
    foreach ($library['variants'] as $variant_name => &$variant) {
      $callback($variant, NULL, $variant_name);
    }
  }
}