function public function LibraryInfo::alter

8.x-3.x LibraryInfo.php public LibraryInfo::alter(&$libraries, &$extension = NULL, &$context2 = NULL)

Alters data for a specific hook_TYPE_alter() implementation.


mixed $data: The variable that will be passed to hook_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.

mixed $context1: (optional) An additional variable that is passed by reference.

mixed $context2: (optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.

Overrides AlterInterface::alter


Implements hook_library_info_alter().



Source src/Plugin/Alter/LibraryInfo.php (line 19)

public function alter(&$libraries, &$extension = NULL, &$context2 = NULL) {
  $livereload = $this->theme->livereloadUrl();

  // Disable preprocess on all CSS/JS if "livereload" is enabled.
  if ($livereload) {
    $this->processLibrary($libraries, function(&$info, &$key, $type) {
      if ($type === 'css' || $type === 'js') {
        $info['preprocess'] = FALSE;

  if ($extension === 'bootstrap') {
    // Alter the "livereload.js" placeholder with the correct URL.
    if ($livereload) {
      $libraries['livereload']['js'][$livereload] = $libraries['livereload']['js']['livereload.js'];

    // Alter the framework library based on currently set CDN Provider.

    // Add back deprecated library dependencies that are only available in D8.
    if (((int) substr(\Drupal::VERSION, 0, 1)) < 9) {
      $libraries['drupal.vertical-tabs']['dependencies'][] = 'core/matchmedia';
  // Core replacements.
  elseif ($extension === 'core') {
    // Replace core dialog/jQuery UI implementations with Bootstrap Modals.
    if ($this->theme->getSetting('modal_enabled')) {
      // Replace dependencies if using bridge so jQuery UI is not loaded
      // and remove dialog.jquery-ui.js since the dialog widget isn't loaded.
      if ($this->theme->getSetting('modal_jquery_ui_bridge')) {
        // Remove core's jquery.ui.dialog dependency.
        $key = array_search('core/jquery.ui.dialog', $libraries['drupal.dialog']['dependencies']);
        if ($key !== FALSE) {

        // Remove core's dialog.jquery-ui.js.

        // Add the Modal jQuery UI Bridge.
        $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/dialog';
        $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/modal.jquery.ui.bridge';
      // Otherwise, just append the modal.
      else {
        $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/modal';
        $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/dialog';