4 * Contains \Drupal\bootstrap\Plugin\Setting\Advanced\Cdn\CdnJsdelivrVersion.
7 namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
9 use Drupal\bootstrap\Annotation\BootstrapConstant;
10 use Drupal\bootstrap\Annotation\BootstrapSetting;
11 use Drupal\bootstrap\Bootstrap;
12 use Drupal\bootstrap\Utility\Element;
13 use Drupal\Component\Utility\Html;
14 use Drupal\Core\Annotation\Translation;
15 use Drupal\Core\Form\FormStateInterface;
18 * The "cdn_jsdelivr_version" theme setting.
20 * @ingroup plugins_setting
23 * cdn_provider = "jsdelivr",
24 * id = "cdn_jsdelivr_version",
27 * title = @Translation("Version"),
28 * description = @Translation("Choose the Bootstrap version from jsdelivr"),
29 * defaultValue = @BootstrapConstant("Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION"),
31 * "advanced" = @Translation("Advanced"),
32 * "cdn" = @Translation("CDN (Content Delivery Network)"),
37 class CdnJsdelivrVersion extends CdnProvider {
42 public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
43 $plugin_id = Html::cleanCssIdentifier($this->provider->getPluginId());
44 $setting = $this->getSettingElement($form, $form_state);
46 $setting->setProperty('options', $this->provider->getVersions());
47 $setting->setProperty('ajax', [
48 'callback' => [get_class($this), 'ajaxCallback'],
49 'wrapper' => 'cdn-provider-' . $plugin_id,
52 if (!$this->provider->hasError() && !$this->provider->isImported()) {
53 $setting->setProperty('description', t('These versions are automatically populated by the @provider API upon cache clear and newer versions may appear over time. It is highly recommended the version that the site was built with stays at that version. Until a newer version has been properly tested for updatability by the site maintainer, you should not arbitrarily "update" just because there is a newer version. This can cause many inconsistencies and undesired effects with an existing site.', [
54 '@provider' => $this->provider->getLabel(),
60 * AJAX callback for reloading CDN provider elements.
63 * Nested array of form elements that comprise the form.
64 * @param \Drupal\Core\Form\FormStateInterface $form_state
65 * The current state of the form.
67 public static function ajaxCallback(array $form, FormStateInterface $form_state) {
68 return $form['advanced']['cdn'][$form_state->getValue('cdn_provider', Bootstrap::getTheme()->getSetting('cdn_provider'))];