class CdnVersion

The "cdn_version" theme setting.

Plugin annotation

@BootstrapSetting(
  id = "cdn_version",
  type = "select",
  weight = 2,
  title = @Translation("Version"),
  description = @Translation("Choose a version provided by the CDN Provider."),
  defaultValue = \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION,
  groups = {
    "cdn" = @Translation("CDN (Content Delivery Network)"),
    "cdn_provider" = false,
  },
)

Hierarchy

Expanded class hierarchy of CdnVersion

Related topics

Namespace

Drupal\bootstrap\Plugin\Setting\Advanced\Cdn
Source
class CdnVersion extends CdnProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
    $setting = $this->setCdnProvidersAjax($this->getSettingElement($form, $form_state));

    // Immediately return if the provider doesn't support versions.
    $provider = $this->getProvider();
    if (!$provider->supportsVersions()) {
      $setting->access(FALSE);
      return;
    }

    $setting->setProperty('description', $this->t('These versions are automatically populated by the @provider API.', [
      '@provider' => $provider->getLabel(),
    ]));

    $exceptions = $provider->trackCdnExceptions(function() use ($provider, $setting) {
      $setting->setProperty('options', $provider->getCdnVersions());
    });

    // Check for tracked CDN exceptions.
    if ($exceptions) {
      $setting->setError($this->t('Unable to parse the @provider API to determine available versions.', [
        '@provider' => $provider->getLabel(),
      ]));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function processDeprecatedValues(array $values, array $deprecated) {
    // @todo Remove deprecated setting support in a future release.
    $deprecated = "cdn_{$this->getProvider()->getPluginId()}_version";
    return isset($values[$deprecated]) ? $values[$deprecated] : NULL;
  }

}

Members

Contains filters are case sensitive
Name Modifiers Type Description
CdnProviderBase::$provider protected property The active provider based on form value or theme setting.
CdnProviderBase::ajaxCdnProvidersCallback public static function AJAX callback for reloading CDN Providers.
CdnProviderBase::alterForm public function The alter method to store the code. Overrides SettingBase::alterForm
CdnProviderBase::checkCdnExceptions protected static function Handles any CDN Provider exceptions that may have been thrown.
CdnProviderBase::getCacheTags public function The cache tags associated with this object. Overrides SettingBase::getCacheTags
CdnProviderBase::getProvider protected function Retrieves the active CDN Provider.
CdnProviderBase::setCdnProvidersAjax protected function Sets the #ajax property to rebuild the entire CDN Providers container.
CdnVersion::alterFormElement public function The alter method to store the code. Overrides SettingBase::alterFormElement
CdnVersion::processDeprecatedValues public function Retrieves the value from other deprecated settings. Overrides SettingBase::processDeprecatedValues
FormAutoloadFixTrait::formAutoloadFix public static function Adds the autoload fix include file to the form state.
PluginBase::$theme protected property The currently set theme object.
PluginBase::__construct public function
SettingBase::$autoUserInterface public static property
SettingBase::access public function Indicates whether a setting is accessible. Overrides SettingInterface::access
SettingBase::autoCreateFormElement public function Indicates whether a form element should be created automatically. Overrides SettingInterface::autoCreateFormElement
SettingBase::drupalSettings public function Determines whether a theme setting should added to drupalSettings. Overrides SettingInterface::drupalSettings
SettingBase::getDefaultValue public function Retrieves the setting's default value. Overrides SettingInterface::getDefaultValue
SettingBase::getDescription public function Retrieves the setting's description, if any. Overrides SettingInterface::getDescription
SettingBase::getElement Deprecated public function Overrides SettingInterface::getElement
SettingBase::getElementProperties public function Retrieves all the form properties from the setting definition.
SettingBase::getGroup Deprecated public function Overrides SettingInterface::getGroup
SettingBase::getGroupElement public function Retrieves the group form element the setting belongs to. Overrides SettingInterface::getGroupElement
SettingBase::getGroups public function Retrieves the setting's groups. Overrides SettingInterface::getGroups
SettingBase::getOptions public function Retrieves the settings options, if set. Overrides SettingInterface::getOptions
SettingBase::getSettingElement public function Retrieves the form element for the setting. Overrides SettingInterface::getSettingElement
SettingBase::getSettingValue protected function Retrieves the setting value used to populate the form.
SettingBase::getTitle public function Retrieves the setting's human-readable title. Overrides SettingInterface::getTitle
SettingBase::submitForm public static function Form submission handler. Overrides FormInterface::submitForm
SettingBase::submitFormElement public static function Form submission handler. Overrides FormInterface::submitFormElement
SettingBase::validateForm public static function Form validation handler. Overrides FormInterface::validateForm
SettingBase::validateFormElement public static function Form validation handler. Overrides FormInterface::validateFormElement