diff --git a/bootstrap.drush.inc b/bootstrap.drush.inc index 1d94fa18896d1cc6a8adf5656fe04bf2bd48f660..d87978f1fe431da4be628e2c438b2159e44351c6 100644 --- a/bootstrap.drush.inc +++ b/bootstrap.drush.inc @@ -69,48 +69,56 @@ function _drush_bootstrap_generate_docs_settings(Theme $bootstrap) { $output[] = '```'; // Determine the groups. - $groups = []; + $groups = [ + 'general' => [], + 'components' => [], + 'javascript' => [], + 'cdn' => [], + 'advanced' => [], + ]; foreach ($bootstrap->getSettingPlugin() as $setting) { // Only get the first two groups (we don't need 3rd, or more, levels). - $_groups = array_slice($setting->getGroups(), 0, 2, FALSE); + $_groups = array_filter(array_slice($setting->getGroups(), 0, 2, FALSE)); if (!$_groups) { continue; } - $groups[implode(' > ', $_groups)][] = $setting->getPluginDefinition(); + $groups[array_keys($_groups)[0]][implode(' > ', $_groups)][] = $setting->getPluginDefinition(); } // Generate a table of each group's settings. - foreach ($groups as $group => $settings) { - $output[] = ''; - $output[] = '---'; - $output[] = ''; - $output[] = "### $group"; - $output[] = ''; - $output[] = '
Setting name | '; - $output[] = 'Description and default value | '; - $output[] = '
---|---|
'; - $output[] = $definition['id']; - $output[] = ' | '; - $output[] = '';
- $output[] = ' ';
- $output[] = str_replace('"e;', '"', wordwrap($definition['description']));
- $output[] = ' ';
- $output[] = ' ';
- $output[] = ' | ';
- $output[] = '
Setting name | '; + $output[] = 'Description and default value | '; + $output[] = '
---|---|
'; + $output[] = $definition['id']; + $output[] = ' | '; + $output[] = '';
+ $output[] = ' ';
+ $output[] = str_replace('"e;', '"', wordwrap($definition['description']));
+ $output[] = ' ';
+ $output[] = ' ';
+ $output[] = ' | ';
+ $output[] = '
Setting name | -Description and default value | -
---|---|
-include_deprecated - | -
-
-Enabling this setting will include any
- deprecated.php file
-found in your theme or base themes.
-
- |
-
-suppress_deprecated_warnings - | -
-
-Enable this setting if you wish to suppress deprecated warning messages.
-WARNING: Suppressing these messages does
-not "fix" the problem and you will inevitably encounter issues
-when they are removed in future updates. Only use this setting in extreme
-and necessary circumstances.
-
-
- |
-
-cdn_provider - | -
-
-Choose between jsdelivr or a custom cdn source.
-
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_custom_css - | -
-
-It is best to use
- https protocols here as it will allow more
-flexibility if the need ever arises.
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_custom_css_min - | -
-
-Additionally, you can provide the minimized version of the file. It will be
-used instead if site aggregation is enabled.
-
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_custom_js - | -
-
-It is best to use
- https protocols here as it will allow more
-flexibility if the need ever arises.
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_custom_js_min +button_colorize |
-Additionally, you can provide the minimized version of the file. It will be
-used instead if site aggregation is enabled.
+Adds classes to buttons based on their text value.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_jsdelivr_version +button_iconize |
-Choose the Bootstrap version from jsdelivr
+Adds icons to buttons based on the text value
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-cdn_jsdelivr_theme +button_size |
-Choose the example Bootstrap Theme provided by Bootstrap or one of the
-Bootswatch themes.
+Defines the Bootstrap Buttons specific size
|
@@ -183,7 +70,7 @@ cdn_jsdelivr_theme: bootstrap
---
-### Components > Breadcrumbs
+### General > Container
-breadcrumb - | -
-
-Show or hide the Breadcrumbs
-
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-breadcrumb_home - | -
-
-If your site has a module dedicated to handling breadcrumbs already, ensure
-this setting is enabled.
-
-
- |
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-breadcrumb_title +fluid_container |
-If your site has a module dedicated to handling breadcrumbs already, ensure
-this setting is disabled.
+Uses the
.container-fluid class instead of
+.container .
|
@@ -242,7 +100,7 @@ breadcrumb_title: 1
---
-### Components > Navbar
+### General > Forms
-navbar_inverse - | -
-
-Select if you want the inverse navbar style.
-
-
- |
-
-navbar_position +forms_has_error_value_toggle |
-Determines where the navbar is positioned on the page.
+If an element has a
.has-error class attached to it, enabling
+this will automatically remove that class when a value is entered.
|
Setting name | -Description and default value | -
---|---|
-region_wells +forms_required_has_error |
-Enable the
.well , .well-sm or
-.well-lg classes for specified regions.
+If an element in a form is required, enabling this will always display the
+element with a .has-error class. This turns the element red
+and helps in usability for determining which form elements are required to
+submit the form.
|
Setting name | -Description and default value | -||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-button_colorize +forms_smart_descriptions |
-Adds classes to buttons based on their text value.
+Convert descriptions into tooltips (must be enabled) automatically based on
+certain criteria. This helps reduce the, sometimes unnecessary, amount of
+noise on a page full of form elements.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
-button_iconize +forms_smart_descriptions_allowed_tags |
-Adds icons to buttons based on the text value
+Prevents descriptions from becoming tooltips by checking for HTML not in
+the list above (i.e. links). Separate by commas. To disable this filtering
+criteria, leave an empty value.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
-button_size +forms_smart_descriptions_limit |
-Defines the Bootstrap Buttons specific size
+Prevents descriptions from becoming tooltips by checking the character
+length of the description (HTML is not counted towards this limit). To
+disable this filtering criteria, leave an empty value.
|
@@ -381,7 +195,7 @@ button_size: ''
---
-### General > Container
+### General > Images
-fluid_container +image_responsive |
-Uses the
.container-fluid class instead of
-.container .
+Images in Bootstrap 3 can be made responsive-friendly via the addition of
+the .img-responsive class. This applies max-width:
+100%; and height: auto; to the image so that it scales
+nicely to the parent element.
+ |
+ ||||||||||||||||||||||||||||||||||||||||||||||||||
+image_shape + | +
+
+Add classes to an
+ <img> element to easily style images
+in any project.
+
|
@@ -411,7 +242,7 @@ fluid_container: 0
---
-### General > Forms
+### General > Tables
-forms_has_error_value_toggle +table_bordered |
-If an element has a
.has-error class attached to it, enabling
-this will automatically remove that class when a value is entered.
+Add borders on all sides of the table and cells.
|
||||||||||||||||||||||||||||||||||||||||
-forms_required_has_error +table_condensed |
-If an element in a form is required, enabling this will always display the
-element with a
.has-error class. This turns the element red
-and helps in usability for determining which form elements are required to
-submit the form.
+Make tables more compact by cutting cell padding in half.
|
||||||||||||||||||||||||||||||||||||||||
-forms_smart_descriptions +table_hover |
-Convert descriptions into tooltips (must be enabled) automatically based on
-certain criteria. This helps reduce the, sometimes unnecessary, amount of
-noise on a page full of form elements.
+Enable a hover state on table rows.
|
||||||||||||||||||||||||||||||||||||||||
-forms_smart_descriptions_allowed_tags +table_striped |
-Prevents descriptions from becoming tooltips by checking for HTML not in
-the list above (i.e. links). Separate by commas. To disable this filtering
-criteria, leave an empty value.
+Add zebra-striping to any table row within the
<tbody> .
|
||||||||||||||||||||||||||||||||||||||||
-forms_smart_descriptions_limit +table_responsive |
-Prevents descriptions from becoming tooltips by checking the character
-length of the description (HTML is not counted towards this limit). To
-disable this filtering criteria, leave an empty value.
+Wraps tables with
.table-responsive to make them horizontally
+scroll when viewing them on devices under 768px. When viewing on devices
+larger than 768px, you will not see a difference in the presentational
+aspect of these tables. The Automatic option will only apply
+this setting for front-end facing tables, not the tables in administrative
+areas.
|
@@ -506,7 +332,7 @@ forms_smart_descriptions_limit: '250'
---
-### General > Images
+### Components > Breadcrumbs
-image_responsive +breadcrumb |
-Images in Bootstrap 3 can be made responsive-friendly via the addition of
-the
+ .img-responsive class. This applies max-width:
-100%; and height: auto; to the image so that it scales
-nicely to the parent element.
+Show or hide the Breadcrumbs
+
+ |
+ ||||||
+breadcrumb_home + | +
+
+If your site has a module dedicated to handling breadcrumbs already, ensure
+this setting is enabled.
|
||||||
-image_shape +breadcrumb_title |
-Add classes to an
<img> element to easily style images
-in any project.
+If your site has a module dedicated to handling breadcrumbs already, ensure
+this setting is disabled.
|
@@ -553,7 +391,7 @@ image_shape: ''
---
-### General > Tables
+### Components > Navbar
-table_bordered +navbar_inverse |
-Add borders on all sides of the table and cells.
+Select if you want the inverse navbar style.
|
-table_condensed +navbar_position |
-Make tables more compact by cutting cell padding in half.
+Determines where the navbar is positioned on the page.
|
-table_hover - | -
-
-Enable a hover state on table rows.
-
-
|
<tbody>
.
-
-table_striped: 1
+---
-
- Setting name | +Description and default value | +
---|---|
-table_responsive +region_wells |
-Wraps tables with
.table-responsive to make them horizontally
-scroll when viewing them on devices under 768px. When viewing on devices
-larger than 768px, you will not see a difference in the presentational
-aspect of these tables. The Automatic option will only apply
-this setting for front-end facing tables, not the tables in administrative
-areas.
+Enable the .well , .well-sm or
+.well-lg classes for specified regions.
|
@@ -1130,5 +960,175 @@ tooltip_trigger: hover
Setting name | +Description and default value | +
---|---|
+cdn_provider + | +
+
+Choose the CDN Provider used to load Bootstrap resources.
+
+
+ |
+
+cdn_custom_css + | +
+
+It is best to use
+ https protocols here as it will allow more
+flexibility if the need ever arises.
+
+ |
+
+cdn_custom_css_min + | +
+
+Additionally, you can provide the minimized version of the file. It will be
+used instead if site aggregation is enabled.
+
+
+ |
+
+cdn_custom_js + | +
+
+It is best to use
+ https protocols here as it will allow more
+flexibility if the need ever arises.
+
+ |
+
+cdn_custom_js_min + | +
+
+Additionally, you can provide the minimized version of the file. It will be
+used instead if site aggregation is enabled.
+
+
+ |
+
+cdn_jsdelivr_version + | +
+
+Choose the Bootstrap version from jsdelivr
+
+
+ |
+
+cdn_jsdelivr_theme + | +
+
+Choose the example Bootstrap Theme provided by Bootstrap or one of the
+Bootswatch themes.
+
+
+ |
+
Setting name | +Description and default value | +
---|---|
+include_deprecated + | +
+
+Enabling this setting will include any
+ deprecated.php file
+found in your theme or base themes.
+
+ |
+
+suppress_deprecated_warnings + | +
+
+Enable this setting if you wish to suppress deprecated warning messages.
+WARNING: Suppressing these messages does
+not "fix" the problem and you will inevitably encounter issues
+when they are removed in future updates. Only use this setting in extreme
+and necessary circumstances.
+
+
+ |
+
https
protocols here as it will allow more flexibility if the need ever arises."),
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "custom" = false,
* },
* )
*/
-class CdnCustomCss extends SettingBase {
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return ['library_info'];
- }
-
-}
+class CdnCustomCss extends CdnProviderBase {}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnCustomCssMin.php b/src/Plugin/Setting/Advanced/Cdn/CdnCustomCssMin.php
index 5f61c3b3dca6d3f3d5203de6f9077acc906e9825..6894481c6b737d1f52d3bf59aef06706bf63b988 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnCustomCssMin.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnCustomCssMin.php
@@ -2,8 +2,6 @@
namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
-use Drupal\bootstrap\Plugin\Setting\SettingBase;
-
/**
* The "cdn_custom_css_min" theme setting.
*
@@ -18,19 +16,10 @@ use Drupal\bootstrap\Plugin\Setting\SettingBase;
* defaultValue = "https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css",
* description = @Translation("Additionally, you can provide the minimized version of the file. It will be used instead if site aggregation is enabled."),
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "custom" = false,
* },
* )
*/
-class CdnCustomCssMin extends SettingBase {
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return ['library_info'];
- }
-
-}
+class CdnCustomCssMin extends CdnProviderBase {}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnCustomJs.php b/src/Plugin/Setting/Advanced/Cdn/CdnCustomJs.php
index c88936c788b4284ade0d0b31d096df3b75ceb10a..8b5e93168422d17abce91a6fa2ccbe84566149b5 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnCustomJs.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnCustomJs.php
@@ -2,8 +2,6 @@
namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
-use Drupal\bootstrap\Plugin\Setting\SettingBase;
-
/**
* The "cdn_custom_js" theme setting.
*
@@ -18,19 +16,10 @@ use Drupal\bootstrap\Plugin\Setting\SettingBase;
* defaultValue = "https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.js",
* description = @Translation("It is best to use https
protocols here as it will allow more flexibility if the need ever arises."),
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "custom" = false,
* },
* )
*/
-class CdnCustomJs extends SettingBase {
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return ['library_info'];
- }
-
-}
+class CdnCustomJs extends CdnProviderBase {}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnCustomJsMin.php b/src/Plugin/Setting/Advanced/Cdn/CdnCustomJsMin.php
index c571d54cda49f051e1daf763f34c4eb2d9ab7541..ccf49fabcc802a007b1079326b9b18806fb1a171 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnCustomJsMin.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnCustomJsMin.php
@@ -2,8 +2,6 @@
namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
-use Drupal\bootstrap\Plugin\Setting\SettingBase;
-
/**
* The "cdn_custom_js_min" theme setting.
*
@@ -18,19 +16,10 @@ use Drupal\bootstrap\Plugin\Setting\SettingBase;
* defaultValue = "https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js",
* description = @Translation("Additionally, you can provide the minimized version of the file. It will be used instead if site aggregation is enabled."),
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "custom" = false,
* },
* )
*/
-class CdnCustomJsMin extends SettingBase {
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return ['library_info'];
- }
-
-}
+class CdnCustomJsMin extends CdnProviderBase {}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrTheme.php b/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrTheme.php
index ae70749b7ed44a9d822293fb330a00f45e7d008f..76d9eb1991adf0eed40dedbaad0ebb47b88625a2 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrTheme.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrTheme.php
@@ -20,34 +20,43 @@ use Drupal\Core\Form\FormStateInterface;
* empty_option = @Translation("Bootstrap (default)"),
* empty_value = "bootstrap",
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "jsdelivr" = false,
* },
* )
*/
-class CdnJsdelivrTheme extends CdnProvider {
+class CdnJsdelivrTheme extends CdnProviderBase {
/**
* {@inheritdoc}
*/
- public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
- $setting = $this->getSettingElement($form, $form_state);
+ public function buildCdnProviderElement(Element $setting, FormStateInterface $form_state) {
$version = $form_state->getValue('cdn_jsdelivr_version', $this->theme->getSetting('cdn_jsdelivr_version'));
$themes = $this->provider->getCdnThemes($version);
- $setting->setProperty('suffix', '');
- $setting->setProperty('description', t('Choose the example Bootstrap Theme provided by Bootstrap or one of the many, many Bootswatch themes!', [
- ':bootswatch' => 'https://bootswatch.com',
- ':bootstrap_theme' => 'https://getbootstrap.com/docs/3.4/examples/theme/',
- ]));
-
$options = [];
foreach ($themes as $theme => $data) {
$options[$theme] = $data['title'];
}
$setting->setProperty('options', $options);
+ $setting->setProperty('suffix', '');
+
+ if ($this->provider->getCdnExceptions(FALSE)) {
+ $setting->setProperty('description', t('Unable to parse the @provider API to determine themes. This theme is simply the default CSS supplied by the framework.', [
+ '@provider' => $this->provider->getLabel(),
+ ]));
+ }
+ else {
+ $setting->setProperty('description', t('Choose the example Bootstrap Theme provided by Bootstrap or one of the many, many Bootswatch themes!', [
+ ':bootswatch' => 'https://bootswatch.com',
+ ':bootstrap_theme' => 'https://getbootstrap.com/docs/3.4/examples/theme/',
+ ]));
+ }
+
+ // Check for any CDN failure(s).
+ $this->checkCdnExceptions();
}
}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrVersion.php b/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrVersion.php
index d15b25ce20c112e54d64488da20825884d6cb0b0..a372787db18f3d0de3d8c94359c852d2c5bf8f45 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrVersion.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnJsdelivrVersion.php
@@ -21,48 +21,38 @@ use Drupal\Core\Form\FormStateInterface;
* description = @Translation("Choose the Bootstrap version from jsdelivr"),
* defaultValue = @BootstrapConstant("Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION"),
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* "jsdelivr" = false,
* },
* )
*/
-class CdnJsdelivrVersion extends CdnProvider {
+class CdnJsdelivrVersion extends CdnProviderBase {
/**
* {@inheritdoc}
*/
- public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
- // Add autoload fix to make sure AJAX callbacks work.
- static::formAutoloadFix($form_state);
-
+ public function buildCdnProviderElement(Element $setting, FormStateInterface $form_state) {
$plugin_id = Html::cleanCssIdentifier($this->provider->getPluginId());
- $setting = $this->getSettingElement($form, $form_state);
- $versions = $this->provider->getCdnVersions();
-
- $setting->setProperty('options', $versions);
+ $setting->setProperty('options', $this->provider->getCdnVersions());
$setting->setProperty('ajax', [
- 'callback' => [get_class($this), 'ajaxCallback'],
+ 'callback' => [get_class($this), 'ajaxProviderCallback'],
'wrapper' => 'cdn-provider-' . $plugin_id,
]);
- if (!$this->provider->hasError() && !$this->provider->isImported()) {
- $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.', [
+ if ($this->provider->getCdnExceptions(FALSE)) {
+ $setting->setProperty('description', t('Unable to parse the @provider API to determine versions. This version is the default version supplied by the base theme.', [
+ '@provider' => $this->provider->getLabel(),
+ ]));
+ }
+ else {
+ $setting->setProperty('description', t('These versions are automatically populated by the @provider API. While 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.', [
'@provider' => $this->provider->getLabel(),
]));
}
- }
- /**
- * AJAX callback for reloading CDN provider elements.
- *
- * @param array $form
- * Nested array of form elements that comprise the form.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The current state of the form.
- */
- public static function ajaxCallback(array $form, FormStateInterface $form_state) {
- return $form['advanced']['cdn'][$form_state->getValue('cdn_provider', Bootstrap::getTheme()->getSetting('cdn_provider'))];
+ // Check for any CDN failure(s).
+ $this->checkCdnExceptions();
}
}
diff --git a/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php b/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
index a0741dbd18a74e0876c235f50e91da102e42f5b1..fa7b0f45adc8b977cd4c7d5cfce721a2259be821 100644
--- a/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
+++ b/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
@@ -3,10 +3,9 @@
namespace Drupal\bootstrap\Plugin\Setting\Advanced\Cdn;
use Drupal\bootstrap\Bootstrap;
+use Drupal\bootstrap\Plugin\Form\SystemThemeSettings;
use Drupal\bootstrap\Plugin\Provider\ProviderInterface;
use Drupal\bootstrap\Plugin\ProviderManager;
-use Drupal\bootstrap\Plugin\Setting\SettingBase;
-use Drupal\bootstrap\Traits\FormAutoloadFixTrait;
use Drupal\bootstrap\Utility\Element;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
@@ -21,88 +20,68 @@ use Drupal\Core\Form\FormStateInterface;
* id = "cdn_provider",
* type = "select",
* title = @Translation("CDN Provider"),
- * description = @Translation("Choose between jsdelivr or a custom cdn source."),
+ * description = @Translation("Choose the CDN Provider used to load Bootstrap resources."),
* defaultValue = "jsdelivr",
* empty_value = "",
* weight = -1,
* groups = {
- * "advanced" = @Translation("Advanced"),
* "cdn" = @Translation("CDN (Content Delivery Network)"),
+ * "cdn_provider" = false,
* },
* options = { },
* )
*/
-class CdnProvider extends SettingBase {
-
- use FormAutoloadFixTrait;
-
- /**
- * The current provider.
- *
- * @var \Drupal\bootstrap\Plugin\Provider\ProviderInterface
- */
- protected $provider;
-
- /**
- * The current provider manager instance.
- *
- * @var \Drupal\bootstrap\Plugin\ProviderManager
- */
- protected $providerManager;
-
- /**
- * {@inheritdoc}
- */
- public function __construct(array $configuration, $plugin_id, $plugin_definition) {
- parent::__construct($configuration, $plugin_id, $plugin_definition);
- $this->providerManager = new ProviderManager($this->theme);
- $this->provider = $this->providerManager->get(isset($plugin_definition['cdn_provider']) ? $plugin_definition['cdn_provider'] : NULL);
- }
+class CdnProvider extends CdnProviderBase {
/**
* {@inheritdoc}
*/
public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
- // Add autoload fix to make sure AJAX callbacks work.
- static::formAutoloadFix($form_state);
+ parent::alterFormElement($form, $form_state);
// Retrieve the provider from form values or the setting.
$default_provider = $form_state->getValue('cdn_provider', $this->theme->getSetting('cdn_provider'));
+ // Wrap the default group so it can be replaced via AJAX.
$group = $this->getGroupElement($form, $form_state);
- $description_label = $this->t('NOTE');
- $description = $this->t('Using one of the "CDN Provider" options below is the preferred method for loading Bootstrap CSS and JS on simpler sites that do not use a site-wide CDN. Using a "CDN Provider" for loading Bootstrap, however, does mean that it depends on a third-party service. There is no obligation or commitment by these third-parties that guarantees any up-time or service quality. If you need to customize Bootstrap and have chosen to compile the source code locally (served from this site), you must disable the "CDN Provider" option below by choosing "- None -" and alternatively enable a site-wide CDN implementation. All local (served from this site) versions of Bootstrap will be superseded by any enabled "CDN Provider" below. Do not do both.');
- $group->setProperty('description', ' ');
- $group->setProperty('open', !!$default_provider);
+ $group->setProperty('prefix', '