Skip to content

Commit

Permalink
#75: conditionally include css/js based on config
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh committed Dec 12, 2017
1 parent 5c8da02 commit 85e7413
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions kalastatic.module
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ function kalastatic_library_info_build() {

// Build and array of js file paths.
$js = [];
foreach ($config['scripts']['footer'] as $js_path) {
// Don't pull in the special files we built to handle Drupal compatibility
// on the Kalastatic side.
$disallowed = strpos($js_path, 'drupal_pre') || strpos($js_path, 'drupal_post');
if (!$disallowed) {
$js[$build_path . '/' . $js_path] = [];
}
foreach ($config['scripts']['footer']['all'] as $js_path) {
$js[$build_path . '/' . $js_path] = [];
}

// Add the css and js to the library.
Expand All @@ -71,8 +66,18 @@ function kalastatic_library_info_build() {
* Implements hook_page_attachments().
*/
function kalastatic_page_attachments(array &$attachments) {
// Attach library to page.
$attachments['#attached']['library'][] = 'kalastatic/css-js';
// Get the module settings and the active theme.
$module_settings = \Drupal::config('kalastatic.settings');
$ks_themes = $module_settings->get('kalastatic_theme_list');
$active_theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();
xdebug_break();
// Go through the list of themes to see if we should add Kalastatic assets.
foreach ($ks_themes as $name) {
if (!empty($name) && $active_theme == $name) {
// Attach library to this page.
$attachments['#attached']['library'][] = 'kalastatic/css-js';
}
}
}

/**
Expand Down

0 comments on commit 85e7413

Please sign in to comment.