diff --git a/theme-settings.php b/theme-settings.php index 9cffe3c..35e01c5 100644 --- a/theme-settings.php +++ b/theme-settings.php @@ -268,33 +268,42 @@ function bulma_form_system_theme_settings_alter(&$form, FormStateInterface $form // Bulmaswatch settings. $form['bulma_bulmaswatch'] = [ '#type' => 'details', - '#title' => t('Bulmaswatch Theme'), - '#description' => t('Contains settings for custom themes provided by Bulmaswatch; see documentation', [ - '@docs' => Url::fromUri('https://jenil.github.io/bulmaswatch/', - ['attributes' => ['target' => '_blank']]) - ->toString(), + '#title' => t('Bulma Theme'), + '#description' => t('Select a custom theme provided by Bulmaswatch; see documentation.', [ + ':docs' => 'https://jenil.github.io/bulmaswatch', ]), - // Default access to FALSE. - '#access' => FALSE, - ]; - - $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme'] = [ - '#type' => 'select', - '#title' => t('Theme'), - '#description' => t('Select a custom theme.'), - '#options' => [ - 'default' => t('Default'), - ], - '#default_value' => theme_get_setting('bulma_bulmaswatch_theme'), ]; if ($themes = Bulmaswatch::getThemes()) { - $form['bulma_bulmaswatch']['#access'] = TRUE; + $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme'] = [ + '#type' => 'select', + '#title' => t('Theme'), + '#options' => [ + 'default' => t('Default'), + ], + '#default_value' => theme_get_setting('bulma_bulmaswatch_theme'), + ]; + foreach ($themes as $machine_name => $theme) { - $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme']['#options'][$machine_name] = t('%name: %description', ['%name' => $theme['name'], '%description' => $theme['description']]); + $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme']['#options'][$machine_name] = t('@name: @description', ['@name' => $theme['name'], '@description' => $theme['description']]); + $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme_preview_' . $machine_name] = [ + '#type' => 'item', + '#markup' => '

' . t('Preview the %name theme.', [':preview' => $theme['preview'], '%name' => $theme['name']]) . '

', + '#states' => [ + 'visible' => [ + 'select[name="bulma_bulmaswatch_theme"]' => ['value' => $machine_name], + ], + ], + ]; } $form['#submit'][] = 'bulma_form_system_theme_settings_submit'; } + else { + $form['bulma_bulmaswatch']['bulma_bulmaswatch_theme_message'] = [ + '#type' => 'item', + '#markup' => '

' . t('To enable support for custom themes, download a Bulmaswatch release and extract it to libraries/bulmaswatch so that the README.md file is at libraries/bulmaswatch/README.md.', [':download' => 'https://github.com/jenil/bulmaswatch/releases']) . '

', + ]; + } }