Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Alter / LibraryInfo.php
index d91f539cfec0569c6f7cf2e9bea8cea292c3c943..79f1cded05173490c66500b34828c20e7b346af4 100644 (file)
@@ -1,12 +1,7 @@
 <?php
-/**
- * @file
- * Contains \Drupal\bootstrap\Plugin\Alter\LibraryInfo.
- */
 
 namespace Drupal\bootstrap\Plugin\Alter;
 
-use Drupal\bootstrap\Annotation\BootstrapAlter;
 use Drupal\bootstrap\Bootstrap;
 use Drupal\bootstrap\Plugin\PluginBase;
 use Drupal\Component\Utility\NestedArray;
@@ -52,12 +47,12 @@ class LibraryInfo extends PluginBase implements AlterInterface {
       }
 
       // Merge the assets into the library info.
-      $libraries['theme'] = NestedArray::mergeDeepArray([$assets, $libraries['theme']], TRUE);
+      $libraries['framework'] = NestedArray::mergeDeepArray([$assets, $libraries['framework']], TRUE);
 
       // Add a specific version and theme CSS overrides file.
       // @todo This should be retrieved by the Provider API.
       $version = $this->theme->getSetting('cdn_' . $provider->getPluginId() . '_version') ?: Bootstrap::FRAMEWORK_VERSION;
-      $libraries['theme']['version'] = $version;
+      $libraries['framework']['version'] = $version;
       $provider_theme = $this->theme->getSetting('cdn_' . $provider->getPluginId() . '_theme') ?: 'bootstrap';
       $provider_theme = $provider_theme === 'bootstrap' || $provider_theme === 'bootstrap_theme' ? '' : "-$provider_theme";
 
@@ -73,7 +68,7 @@ class LibraryInfo extends PluginBase implements AlterInterface {
           // it isn't added after any potential sub-theme's "theme" category.
           // There's no weight, so it will be added after the provider's assets.
           // @see https://www.drupal.org/node/2770613
-          $libraries['theme']['css']['base'][$overrides] = [];
+          $libraries['framework']['css']['base'][$overrides] = [];
           break;
         }
       }
@@ -82,8 +77,25 @@ class LibraryInfo extends PluginBase implements AlterInterface {
     elseif ($extension === 'core') {
       // Replace core dialog/jQuery UI implementations with Bootstrap Modals.
       if ($this->theme->getSetting('modal_enabled')) {
-        $libraries['drupal.dialog']['override'] = 'bootstrap/drupal.dialog';
-        $libraries['drupal.dialog.ajax']['override'] = 'bootstrap/drupal.dialog.ajax';
+        // 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) {
+            unset($libraries['drupal.dialog']['dependencies'][$key]);
+          }
+
+          // Remove core's dialog.jquery-ui.js.
+          unset($libraries['drupal.dialog']['js']['misc/dialog/dialog.jquery-ui.js']);
+
+          // Add the Modal jQuery UI Bridge.
+          $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/modal.jquery.ui.bridge';
+        }
+        // Otherwise, just append the modal.
+        else {
+          $libraries['drupal.dialog']['dependencies'][] = 'bootstrap/modal';
+        }
       }
     }
   }
@@ -96,7 +108,7 @@ class LibraryInfo extends PluginBase implements AlterInterface {
    * @param callable $callback
    *   The callback to perform processing on the library.
    */
-  public function processLibrary(&$libraries, callable $callback) {
+  public function processLibrary(array &$libraries, callable $callback) {
     foreach ($libraries as &$library) {
       foreach ($library as $type => $definition) {
         if (is_array($definition)) {