Skip to content

Commit

Permalink
#75: User prompt if no theme is chosen and bail out so we don't get a…
Browse files Browse the repository at this point in the history
…n error.
  • Loading branch information
Josh committed Dec 16, 2017
1 parent 0b042ef commit 4e8e1c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions kalastatic.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Filesystem\Filesystem;
use Drupal\Core\Url;

/**
* Implements hook_preprocess().
Expand Down Expand Up @@ -71,6 +72,13 @@ function kalastatic_page_attachments(array &$attachments) {
$ks_themes = $module_settings->get('kalastatic_theme_list');
$active_theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();

if ($ks_themes == NULL) {
// Set a message and bail out if no themes have been chosen.
$settings_url = Url::fromRoute('kalastatic.settings');
drupal_set_message(t('Kalastatic requires you to choose the theme(s) you would like it to work with. Go to the <a href="@link">settings page.</a>', array('@link' => $settings_url->toString())), 'error');
return;
}

// Check if the active theme has been chosen.
if (in_array($active_theme, $ks_themes)) {
// Attach library to this page.
Expand Down
3 changes: 2 additions & 1 deletion src/Form/KalastaticSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
foreach ($themes as $mn => $theme) {
$theme_list[$mn] = $theme->info['name'];
}
$theme_list_default = $config->get('kalastatic_theme_list') ?: [];

$form = [
'description' => [
Expand All @@ -71,7 +72,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'checkboxes',
'#title' => $this->t('Include Kalastatic assets for'),
'#options' => $theme_list,
'#default_value' => $config->get('kalastatic_theme_list'),
'#default_value' => $theme_list_default,
'#description' => $this->t('The CSS and Javascript output by Kalastatic will be included when any of the chosen themes are set as the default theme.'),
],
'kalastatic_brand_color' => [
Expand Down

0 comments on commit 4e8e1c4

Please sign in to comment.