Loading bootstrap js from CDN when already using Bootstrap theme breaks few things

Created on 7 March 2021, over 4 years ago
Updated 22 June 2025, 15 days ago

Hello!

I've noticed that my Bootstrap dropdowns stoped working at some point. It seemed the problem appeared only on the pages where the materialize_datetime_picker library was loaded.

It all came back to normal when I commented the line that loads https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js: { type: external } in materialize_datetime_picker.libraries.yml since bootstrap.js v3.4.1 is already loaded by my Bootstrap theme.

My final solution was:

/**
 * Implements hook_library_info_alter().
 */
function patients_library_info_alter(&$libraries, $extension) {
  if ($extension === 'materialize_datetime_picker') {
    array_shift($libraries['materialize_datetime_picker']['js']);
  }
}

So, maybe the module itself should implement a hook_library_info_alter and add the external bootstrap.min.js only if the theme is not bootstrap or a bootstrap subtheme.

My setup is:

Drupal 9.1.5
Bootstrap 8.x-3.23 Subtheme
Bootstrap Materialize DateTime Picker 8.x-1.4

With this html in a page where materialize_datetime_picker is loaded:

        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Dropdown item 1</a></li>
              <li><a href="#">Dropdown item 2</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
🐛 Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

🇷🇴Romania trudog

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024