You are here

function hook_library_alter in Drupal 7

Alters the JavaScript/CSS library registry.

Allows certain, contributed modules to update libraries to newer versions while ensuring backwards compatibility. In general, such manipulations should only be done by designated modules, since most modules that integrate with a certain library also depend on the API of a certain library version.

Parameters

$libraries: The JavaScript/CSS libraries provided by $module. Keyed by internal library name and passed by reference.

$module: The name of the module that registered the libraries.

See also

hook_library()

Related topics

2 functions implement hook_library_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

common_test_library_alter in modules/simpletest/tests/common_test.module
Implements hook_library_alter().
locale_library_alter in modules/locale/locale.module
Implement hook_library_alter().
1 invocation of hook_library_alter()
drupal_get_library in includes/common.inc
Retrieves information for a JavaScript/CSS library.

File

modules/system/system.api.php, line 842
Hooks provided by Drupal core and the System module.

Code

function hook_library_alter(&$libraries, $module) {

  // Update Farbtastic to version 2.0.
  if ($module == 'system' && isset($libraries['farbtastic'])) {

    // Verify existing version is older than the one we are updating to.
    if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) {

      // Update the existing Farbtastic to version 2.0.
      $libraries['farbtastic']['version'] = '2.0';
      $libraries['farbtastic']['js'] = array(
        drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(),
      );
    }
  }
}