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