Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Setting / Advanced / Cdn / CdnJsdelivrTheme.php
1 <?php
2
3 namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
4
5 use Drupal\bootstrap\Utility\Element;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * The "cdn_jsdelivr_theme" theme setting.
10  *
11  * @ingroup plugins_setting
12  *
13  * @BootstrapSetting(
14  *   cdn_provider = "jsdelivr",
15  *   id = "cdn_jsdelivr_theme",
16  *   type = "select",
17  *   title = @Translation("Theme"),
18  *   description = @Translation("Choose the example Bootstrap Theme provided by Bootstrap or one of the Bootswatch themes."),
19  *   defaultValue = "bootstrap",
20  *   empty_option = @Translation("Bootstrap (default)"),
21  *   empty_value = "bootstrap",
22  *   groups = {
23  *     "advanced" = @Translation("Advanced"),
24  *     "cdn" = @Translation("CDN (Content Delivery Network)"),
25  *     "jsdelivr" = false,
26  *   },
27  * )
28  */
29 class CdnJsdelivrTheme extends CdnProvider {
30
31   /**
32    * {@inheritdoc}
33    */
34   public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
35     $setting = $this->getSettingElement($form, $form_state);
36     $themes = $this->provider->getThemes();
37     $version = $form_state->getValue('cdn_jsdelivr_version', $this->theme->getSetting('cdn_jsdelivr_version'));
38
39     $setting->setProperty('suffix', '<div id="bootstrap-theme-preview"></div>');
40     $setting->setProperty('description', t('Choose the example <a href=":bootstrap_theme" target="_blank">Bootstrap Theme</a> provided by Bootstrap or one of the many, many <a href=":bootswatch" target="_blank">Bootswatch</a> themes!', [
41       ':bootswatch' => 'https://bootswatch.com',
42       ':bootstrap_theme' => 'https://getbootstrap.com/docs/3.3/examples/theme/',
43     ]));
44
45     $options = [];
46     if (isset($themes[$version])) {
47       foreach ($themes[$version] as $theme => $data) {
48         $options[$theme] = $data['title'];
49       }
50     }
51     $setting->setProperty('options', $options);
52   }
53
54 }