function bootstrap_library_page_attachments in Bootstrap Library 8
Implements hook_page_attachments().
Use Libraries API to load the js & css files into header.
File
- ./
bootstrap_library.module, line 19 - Primarily Drupal hooks.
Code
function bootstrap_library_page_attachments(array &$page) {
// Don't add the JavaScript and CSS during installation.
if (InstallerKernel::installationAttempted()) {
return;
}
// Don't add the JavaScript and CSS on specified paths or themes.
if (!_bootstrap_library_check_theme() || !_bootstrap_library_check_url()) {
return;
}
$config = \Drupal::config('bootstrap_library.settings');
$cdn = $config
->get('cdn.bootstrap');
if ($cdn) {
$page['#attached']['library'][] = 'bootstrap_library/bootstrap-cdn';
}
else {
$variant_options = [
'source',
'minified',
'composer',
];
$variant = $variant_options[$config
->get('minimized.options')];
switch ($variant) {
case 'minified':
$page['#attached']['library'][] = 'bootstrap_library/bootstrap';
break;
case 'source':
$page['#attached']['library'][] = 'bootstrap_library/bootstrap-dev';
break;
case 'composer':
$page['#attached']['library'][] = 'bootstrap_library/bootstrap-composer';
break;
}
}
}