file CdnVersion.php

Namespace

Drupal\bootstrap\Plugin\Setting\Advanced\Cdn
  1. <?php
  2. namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
  3. /**
  4. * Due to BC reasons, this class cannot be moved.
  5. *
  6. * @todo Move namespace up one.
  7. */
  8. use Drupal\bootstrap\Utility\Element;
  9. use Drupal\Core\Form\FormStateInterface;
  10. /**
  11. * The "cdn_version" theme setting.
  12. *
  13. * @ingroup plugins_setting
  14. *
  15. * @BootstrapSetting(
  16. * id = "cdn_version",
  17. * type = "select",
  18. * weight = 2,
  19. * title = @Translation("Version"),
  20. * description = @Translation("Choose a version provided by the CDN Provider."),
  21. * defaultValue = \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION,
  22. * groups = {
  23. * "cdn" = @Translation("CDN (Content Delivery Network)"),
  24. * "cdn_provider" = false,
  25. * },
  26. * )
  27. */
  28. class CdnVersion extends CdnProviderBase {
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
  33. $setting = $this->setCdnProvidersAjax($this->getSettingElement($form, $form_state));
  34. // Immediately return if the provider doesn't support versions.
  35. $provider = $this->getProvider();
  36. if (!$provider->supportsVersions()) {
  37. $setting->access(FALSE);
  38. return;
  39. }
  40. $setting->setProperty('description', $this->t('These versions are automatically populated by the @provider API.', [
  41. '@provider' => $provider->getLabel(),
  42. ]));
  43. $exceptions = $provider->trackCdnExceptions(function () use ($provider, $setting) {
  44. $setting->setProperty('options', $provider->getCdnVersions());
  45. });
  46. // Check for tracked CDN exceptions.
  47. if ($exceptions) {
  48. $setting->setError($this->t('Unable to parse the @provider API to determine available versions.', [
  49. '@provider' => $provider->getLabel(),
  50. ]));
  51. }
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function processDeprecatedValues(array $values, array $deprecated) {
  57. // @todo Remove deprecated setting support in a future release.
  58. $deprecated = "cdn_{$this->getProvider()->getPluginId()}_version";
  59. return isset($values[$deprecated]) ? $values[$deprecated] : NULL;
  60. }
  61. }

Classes

Name Description
CdnVersion The "cdn_version" theme setting.