As it stands, the Bootstrap theme will need to handle loading the Bootstrap library somewhat differently. This issue is to track discussion and progress on that issue. Will expand with more details as time goes on.

Proposal

Library Setup

  • Create a base library that loads the CSS and JS specific to the Drupal Bootstrap theme (override.css etc)
  • Set as a global library via the libraries key in the info.yml file #2246577: Remove 'scripts' and add 'libraries' key to theme info files
  • Create two libraries responsible for including the Bootstrap framework, bootstrap and bootstrap.cdn
  • Define a library responsible for including the Bootstrap framework, called bootstrap
  • bootstrap would be responsible for loading the Bootstrap library locally in the vendor/bootstrap/VERSION/js|css directories
  • Use hook_library_alter() to read theme settings to switch between local or CDN, as well as version, and adding in Bootswatch.
  • bootstrap.cdn would be responsible for loading the Bootstrap library via the official CDN
  • Set the default dependency in the base library to use bootstrap locally
  • Sub-themes or other modules (such as bootstrap_library) could then properly override the Bootstrap library if needed, otherwise, Bootstrap remains as the core pillar of the Bootstrap Framework in Drupal

Handling Versioning

  • Include the latest version of Bootstrap (Currently 3.1.1). This would be updated within the 3.x branch as 3.x versions of Bootstrap are released
  • Bootstrap would be placed in vendor/bootstrap/VERSION to aid in updating from one version to another.
  • Make it clear that we DO NOT support anything in the vendor directory
  • By default, both the bootstrap and bootstrap.cdn libraries would use the latest version of Bootstrap 3.x

Benefits

While using hook_*_alter() works for adding in the Bootstrap library, this is the normal way for themes and modules to operate, thus it standardizes Bootstrap with Drupal 8. This still allows for us to do any altering of the included CSS/JS libraries via hook_library_alter(). Overall this should bring us in line with Drupal 8 best practice as well as simplify the Bootstrap framework loading process.

This would also properly register the Bootstrap framework, however the themer decides to include it so that other themes and modules could use it.

Comments

  • Commit 113d9dd on 8.x-3.x by ryan.armstrong:
    Issue #2247533 by ryan.armstrong: Commenting out some code. Will handle...
ryan.armstrong’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Closing this issue as after getting through it, it turns out its just a duplicate of #2149561: Ensure jquery.once library is loaded when theme's bootstrap.js file is loaded.

ryan.armstrong’s picture

ryan.armstrong’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs work
Related issues: +#2246577: Remove 'scripts' and add 'libraries' key to theme info files

Ok, revisiting this. I have completely updated the body of this issue, please re-read. I have currently implemented the libraries.yml and info.yml changes and am now working on the hook_library_alter() implementation.

ryan.armstrong’s picture

Issue summary: View changes
ryan.armstrong’s picture

Issue summary: View changes

After thinking on this, I think we should just have one library defined in the libraries.yml file, called bootstrap that loads the Bootstrap framework locally, and then have the hook_libraries_later() change the paths to the CDN (or vise versa) before the library is attached. Since they will have the same dependencies and other attributes, there isn't much of a need to have two defined libraries.

ryan.armstrong’s picture

Issue summary: View changes
markhalliwell’s picture

Priority: Critical » Normal
Status: Needs work » Postponed

I would like to postpone this for now. This subject is difficult in nature as there are many ways to provide the resources. I'll be thinking about it, but in the mean time I think it would be more beneficial to start the template conversions.

  • ryan.armstrong committed 113d9dd on 8.x-3.x.x
    Issue #2247533 by ryan.armstrong: Commenting out some code. Will handle...
markhalliwell’s picture

Assigned: ryan.armstrong » Unassigned
Status: Postponed » Closed (duplicate)
Related issues: +#2397407: Move CSS/JS altering to Libraries API