4 * This contains deprecated functions that will be removed in a future release.
7 use Drupal\bootstrap\Bootstrap;
8 use Drupal\bootstrap\Plugin\ProviderManager;
9 use Drupal\bootstrap\Utility\Element;
10 use Drupal\bootstrap\Utility\Unicode;
11 use Drupal\Component\Utility\NestedArray;
14 * The base file system path for CDN providers.
16 * @deprecated Will be removed in a future release.
20 * echo BOOTSTRAP_CDN_PROVIDER_PATH;
23 * use Drupal\bootstrap\Plugin\ProviderManager;
24 * echo ProviderManager::FILE_PATH;
27 * @see \Drupal\bootstrap\Plugin\ProviderManager::FILE_PATH
29 define('BOOTSTRAP_CDN_PROVIDER_PATH', ProviderManager::FILE_PATH);
32 * The current supported Bootstrap framework major version number.
34 * @deprecated Will be removed in a future release.
38 * echo BOOTSTRAP_VERSION_MAJOR;
41 * use Drupal\bootstrap\Bootstrap;
42 * echo substr(Bootstrap::FRAMEWORK_VERSION, 0, 1);
45 * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
47 define('BOOTSTRAP_VERSION_MAJOR', substr(Bootstrap::FRAMEWORK_VERSION, 0, 1));
50 * The current supported Bootstrap framework minor version number.
52 * @deprecated Will be removed in a future release.
56 * echo BOOTSTRAP_VERSION_MINOR;
59 * use Drupal\bootstrap\Bootstrap;
60 * echo substr(Bootstrap::FRAMEWORK_VERSION, 2, 1);
63 * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
65 define('BOOTSTRAP_VERSION_MINOR', substr(Bootstrap::FRAMEWORK_VERSION, 2, 1));
68 * The current supported Bootstrap framework patch version number.
70 * @deprecated Will be removed in a future release.
74 * echo BOOTSTRAP_VERSION_PATCH;
77 * use Drupal\bootstrap\Bootstrap;
78 * echo substr(Bootstrap::FRAMEWORK_VERSION, 4, 1);
81 * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
83 define('BOOTSTRAP_VERSION_PATCH', substr(Bootstrap::FRAMEWORK_VERSION, 4, 1));
86 * The current supported Bootstrap framework version.
88 * @deprecated Will be removed in a future release.
92 * echo BOOTSTRAP_VERSION;
95 * use Drupal\bootstrap\Bootstrap;
96 * echo Bootstrap::FRAMEWORK_VERSION;
99 * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
101 define('BOOTSTRAP_VERSION', Bootstrap::FRAMEWORK_VERSION);
104 * Adds a class to an element's render array.
106 * @param string|array $class
107 * An individual class or an array of classes to add.
108 * @param array $element
109 * The individual renderable array element. It is possible to also pass the
110 * $variables parameter in [pre]process functions and it will logically
111 * determine the correct path to that particular theme hook's classes array.
112 * Passed by reference.
113 * @param string $property
114 * Determines which attributes array to retrieve. By default, this is the
115 * element's normal "attributes", but it could also be one of the following:
116 * - "content_attributes"
117 * - "input_group_attributes"
118 * - "title_attributes"
119 * - "wrapper_attributes".
121 * @deprecated Will be removed in a future release.
125 * _bootstrap_add_class('my-class', $element);
128 * use Drupal\bootstrap\Utility\Element;
129 * Element::create($element)->addClass('my-class');
132 * @see \Drupal\bootstrap\Utility\Element::addClass()
134 function _bootstrap_add_class($class, array &$element, $property = 'attributes') {
135 Bootstrap::deprecated();
136 Element::create($element)->addClass($class, $property);
140 * Adds a specific Bootstrap class to color a button based on its text value.
142 * @param array $element
143 * The form element, passed by reference.
145 * @deprecated Will be removed in a future release.
149 * _bootstrap_colorize_button($element);
152 * use Drupal\bootstrap\Utility\Element;
153 * Element::create($element)->colorize();
156 * @see \Drupal\bootstrap\Utility\Element::colorize()
158 function _bootstrap_colorize_button(array &$element) {
159 Bootstrap::deprecated();
160 Element::create($element)->colorize();
164 * Matches a Bootstrap class based on a string value.
166 * @param string $string
167 * The string to match classes against.
168 * @param string $default
169 * The default class to return if no match is found.
172 * The Bootstrap class matched against the value of $haystack or $default if
173 * no match could be made.
175 * @deprecated Will be removed in a future release.
179 * $class = _bootstrap_colorize_text($string, $default);
182 * use Drupal\bootstrap\Bootstrap;
183 * $class = Bootstrap::cssClassFromString($string, $default);
186 * @see \Drupal\bootstrap\Bootstrap::cssClassFromString()
188 function _bootstrap_colorize_text($string, $default = '') {
189 Bootstrap::deprecated();
190 return Bootstrap::cssClassFromString($string, $default);
194 * Wrapper for the core file_scan_directory() function.
196 * Finds all files that match a given mask in a given directory and then caches
197 * the results. A general site cache clear will force new scans to be initiated
198 * for already cached directories.
201 * The base directory or URI to scan, without trailing slash.
202 * @param string $mask
203 * The preg_match() regular expression of the files to find.
204 * @param array $options
205 * Additional options to pass to file_scan_directory().
208 * An associative array (keyed on the chosen key) of objects with 'uri',
209 * 'filename', and 'name' members corresponding to the matching files.
211 * @deprecated Will be removed in a future release.
215 * $files = _bootstrap_file_scan_directory($theme_path . '/js', '/\.js$/');
218 * use Drupal\bootstrap\Bootstrap;
219 * $files = Bootstrap::getTheme()->fileScan('/\.js$/', 'js');
222 * @see \Drupal\bootstrap\Theme::fileScan()
223 * @see file_scan_directory()
225 function _bootstrap_file_scan_directory($dir, $mask, array $options = []) {
226 Bootstrap::deprecated();
227 $theme = Bootstrap::getTheme();
228 $dir = preg_replace('/^' . preg_quote($theme->getPath()) . '\//', '', $dir);
229 return $theme->fileScan($mask, $dir, $options);
233 * Retrieves an element's "attributes" array.
235 * @param array $element
236 * The individual renderable array element, passed by reference.
237 * @param string $property
238 * Determines which attributes array to retrieve. By default, this is the
239 * element's normal "attributes", but it could also be one of the following:
240 * - "content_attributes"
241 * - "input_group_attributes"
242 * - "title_attributes"
243 * - "wrapper_attributes".
246 * The attributes array.
248 * @deprecated Will be removed in a future release.
252 * $attributes = &_bootstrap_get_attributes($element);
253 * $attributes['class'][] = 'my-class';
256 * use Drupal\bootstrap\Utility\Element;
257 * $attributes = &Element::create($element)->getAttributes();
258 * $attributes['class'][] = 'my-class';
261 * @see \Drupal\bootstrap\Utility\Element::getAttributes()
263 function &_bootstrap_get_attributes(array &$element, $property = 'attributes') {
264 Bootstrap::deprecated();
265 return Element::create($element)->getAttributes($property);
269 * Returns a list of base themes for active or provided theme.
271 * @param string $theme_key
272 * The machine name of the theme to check, if not set the active theme name
274 * @param bool $include_theme_key
275 * Whether to append the returned list with $theme_key.
278 * An indexed array of base themes.
280 * @deprecated Will be removed in a future release.
283 * // Before (including active theme).
284 * $base_themes = _bootstrap_get_base_themes(NULL, TRUE);
286 * // Before (excluding active theme).
287 * $base_themes = _bootstrap_get_base_themes('my_subtheme');
289 * // After (including active theme).
290 * use Drupal\bootstrap\Bootstrap;
291 * $theme = Bootstrap::getTheme();
292 * $base_themes = array_keys($theme->getAncestry());
294 * // After (excluding active theme).
295 * use Drupal\bootstrap\Bootstrap;
296 * $my_subtheme = Bootstrap::getTheme('my_subtheme');
297 * $base_themes = array_keys($my_subtheme->getAncestry());
298 * array_pop($base_themes);
301 * @see \Drupal\bootstrap\Theme::getAncestry()
303 function _bootstrap_get_base_themes($theme_key = NULL, $include_theme_key = FALSE) {
304 Bootstrap::deprecated();
305 $themes = array_keys(Bootstrap::getTheme($theme_key)->getAncestry());
306 if (!$include_theme_key) {
313 * Retrieves an element's "class" attribute array.
315 * @param array $element
316 * The individual renderable array element, passed by reference.
317 * @param string $property
318 * Determines which attributes array to retrieve. By default, this is the
319 * element's normal "attributes", but it could also be one of the following:
320 * - "content_attributes"
321 * - "input_group_attributes"
322 * - "title_attributes"
323 * - "wrapper_attributes".
328 * @deprecated Will be removed in a future release. There is no replacement.
332 * $classes = &_bootstrap_get_classes($element);
333 * $classes[] = 'my-class';
336 * use Drupal\bootstrap\Utility\Element;
337 * $classes = &Element::create($element)->getClasses();
338 * $classes[] = 'my-class';
341 * @see \Drupal\bootstrap\Utility\Element::getClasses()
343 function &_bootstrap_get_classes(array &$element, $property = 'attributes') {
344 Bootstrap::deprecated();
345 return Element::create($element)->getClasses($property);
349 * Returns a list of available Bootstrap Glyphicons.
351 * @param string $version
352 * The specific version of glyphicons to return. If not set, the latest
353 * BOOTSTRAP_VERSION will be used.
356 * An associative array of icons keyed by their classes.
358 * @deprecated Will be removed in a future release.
362 * $glyphicons = _bootstrap_glyphicons($version);
365 * use Drupal\bootstrap\Bootstrap;
366 * $glyphicons = Bootstrap::glyphicons($version);
369 * @see \Drupal\bootstrap\Bootstrap::glyphicons()
371 function _bootstrap_glyphicons($version = NULL) {
372 Bootstrap::deprecated();
373 return Bootstrap::glyphicons($version);
377 * Determine whether or not Bootstrap Glyphicons can be used.
379 * @deprecated Will be removed in a future release.
383 * $supported = _bootstrap_glyphicons_supported();
386 * use Drupal\bootstrap\Bootstrap;
387 * $theme = Bootstrap::getTheme();
388 * $supported = $theme->hasGlyphicons();
391 * @see \Drupal\bootstrap\Theme::hasGlyphicons()
393 function _bootstrap_glyphicons_supported() {
394 Bootstrap::deprecated();
395 return Bootstrap::getTheme()->hasGlyphicons();
399 * Returns a specific Bootstrap Glyphicon.
401 * @param string $name
402 * The icon name, minus the "glyphicon-" prefix.
403 * @param string $default
404 * (Optional) The default value to return.
407 * The HTML markup containing the icon defined by $name, $default value if
408 * icon does not exist or returns empty output for whatever reason.
410 * @deprecated Will be removed in a future release.
414 * $icon = _bootstrap_icon($name, $default);
417 * use Drupal\bootstrap\Bootstrap;
418 * use Drupal\bootstrap\Utility\Element;
419 * $icon = (string) Element::createStandalone(Bootstrap::glyphicon($name, ['#markup' => $default]))->renderPlain();
422 * @see \Drupal\bootstrap\Bootstrap::glyphicon()
424 function _bootstrap_icon($name, $default = NULL) {
425 Bootstrap::deprecated();
426 return Element::createStandalone(Bootstrap::glyphicon($name, ['#markup' => $default]))->renderPlain();
430 * Adds an icon to button element based on its text value.
432 * @param array $element
433 * The form element, passed by reference.
435 * @deprecated Will be removed in a future release.
439 * _bootstrap_iconize_button($element);
442 * use Drupal\bootstrap\Utility\Element;
443 * Element::create($element)->setIcon();
446 * @see \Drupal\bootstrap\Utility\Element::setIcon()
448 function _bootstrap_iconize_button(array &$element) {
449 Bootstrap::deprecated();
450 Element::create($element)->setIcon();
454 * Matches a Bootstrap Glyphicon based on a string value.
456 * @param string $string
457 * The string to match classes against.
458 * @param string $default
459 * The default icon to return if no match is found.
462 * The Bootstrap icon matched against the value of $haystack or $default if
463 * no match could be made.
465 * @deprecated Will be removed in a future release.
469 * $icon = _bootstrap_iconize_text($string, $default);
472 * use Drupal\bootstrap\Bootstrap;
473 * $icon = Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
476 * @see \Drupal\bootstrap\Bootstrap::glyphiconFromString()
478 function _bootstrap_iconize_text($string, $default = '') {
479 Bootstrap::deprecated();
480 return Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
484 * Determines if an element is a button.
486 * @param array $element
487 * A render array element.
492 * @deprecated Will be removed in a future release.
496 * $button = _bootstrap_is_button($element);
499 * use Drupal\bootstrap\Utility\Element;
500 * $button = Element::create($element)->isButton();
503 * @see \Drupal\bootstrap\Utility\Element::isButton()
505 function _bootstrap_is_button(array $element) {
506 Bootstrap::deprecated();
507 return Element::create($element)->isButton();
511 * Determines if a string of text is considered "simple".
513 * @param string $string
514 * The string of text to check "simple" criteria on.
515 * @param int|FALSE $length
516 * The length of characters used to determine whether or not $string is
517 * considered "simple". Set explicitly to FALSE to disable this criteria.
518 * @param array|FALSE $allowed_tags
519 * An array of allowed tag elements. Set explicitly to FALSE to disable this
522 * A variable, passed by reference, that indicates whether or not the
523 * string contains HTML.
526 * Returns TRUE if the $string is considered "simple", FALSE otherwise.
528 * @deprecated Will be removed in a future release.
532 * $simple = _bootstrap_is_simple_string($string, $length, $allowed_tags, $html);
535 * use Drupal\bootstrap\Utility\Unicode;
536 * $simple = Unicode::isSimple($string, $length, $allowed_tags, $html);
539 * @see \Drupal\bootstrap\Utility\Unicode::isSimple()
541 function _bootstrap_is_simple_string($string, $length = 250, $allowed_tags = NULL, &$html = FALSE) {
542 Bootstrap::deprecated();
543 return Unicode::isSimple($string, $length, $allowed_tags, $html);
547 * Removes a class from an element's attributes array.
549 * @param string|array $class
550 * An individual class or an array of classes to remove.
551 * @param array $element
552 * The individual renderable array element.
553 * @param string $property
554 * Determines which attributes array to retrieve. By default, this is the
555 * element's normal "attributes", but it could also be one of the following:
556 * - "content_attributes"
557 * - "input_group_attributes"
558 * - "title_attributes"
559 * - "wrapper_attributes".
561 * @deprecated Will be removed in a future release.
565 * _bootstrap_remove_class('my-class', $element);
568 * use Drupal\bootstrap\Utility\Element;
569 * Element::create($element)->removeClass('my-class');
572 * @see \Drupal\bootstrap\Utility\Element::removeClass()
574 function _bootstrap_remove_class($class, array &$element, $property = 'attributes') {
575 Bootstrap::deprecated();
576 Element::create($element)->removeClass($class, $property);
580 * Retrieves a list of available CDN providers for the Bootstrap framework.
582 * @param string $provider
583 * A specific provider data to return.
585 * Toggle determining whether or not to reset the database cache.
587 * @return array|FALSE
588 * An associative array of CDN providers, keyed by their machine name if
589 * $provider is not set. If $provider is set and exists, it's individual
590 * data array will be returned. If $provider is set and the data does not
591 * exist then FALSE will be returned.
593 * @deprecated Will be removed in a future release.
597 * $providers = bootstrap_cdn_provider();
598 * $jsdelivr = bootstrap_cdn_provider('jsdelivr');
601 * use Drupal\bootstrap\Bootstrap;
602 * use Drupal\bootstrap\Plugin\ProviderManager;
604 * $theme = Bootstrap::getTheme();
606 * // Get provider definitions, the "equivalent" for bootstrap_cdn_provider().
607 * $provider_manager = new ProviderManager($theme);
608 * $providers = $provider_manager->getDefinitions();
609 * $jsdelivr = $provider_manager->getDefinition('jsdelivr');
611 * // You should, however, use the the fully initialized classes made
612 * // available through a theme instance.
613 * $providers = $theme->getProviders();
614 * $jsdelivr = $theme->getProvider('jsdelivr');
617 * @see \Drupal\bootstrap\Plugin\ProviderManager
618 * @see \Drupal\bootstrap\Theme::getProviders()
619 * @see \Drupal\bootstrap\Theme::getProvider()
621 function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) {
622 Bootstrap::deprecated();
623 $provider_manager = new ProviderManager(Bootstrap::getTheme());
625 $provider_manager->clearCachedDefinitions();
627 if (isset($provider)) {
628 if ($provider_manager->hasDefinition($provider)) {
629 return $provider_manager->getDefinition($provider);
633 return $provider_manager->getDefinitions();
637 * Converts an element description into a tooltip based on certain criteria.
639 * @param array $element
640 * An element render array, passed by reference.
641 * @param array $target
642 * The target element render array the tooltip is to be attached to, passed
643 * by reference. If not set, it will default to the $element passed.
644 * @param bool $input_only
645 * Toggle determining whether or not to only convert input elements.
647 * The length of characters to determine if description is "simple".
649 * @deprecated Will be removed in a future release.
653 * bootstrap_element_smart_description($element, $target, $input_only, $length);
656 * use Drupal\bootstrap\Utility\Element;
657 * Element::create($element)->smartDescription($target, $input_only, $length);
660 * @see \Drupal\bootstrap\Utility\Element::smartDescription()
662 function bootstrap_element_smart_description(array &$element, array &$target = NULL, $input_only = TRUE, $length = NULL) {
663 Bootstrap::deprecated();
664 Element::create($element)->smartDescription($target, $input_only, $length);
668 * Retrieves CDN assets for the active provider, if any.
670 * @param string|array $type
671 * The type of asset to retrieve: "css" or "js", defaults to an array
672 * array containing both if not set.
673 * @param string $provider
674 * The name of a specific CDN provider to use, defaults to the active provider
675 * set in the theme settings.
676 * @param string $theme
677 * The name of a specific theme the settings should be retrieved from,
678 * defaults to the active theme.
681 * If $type is a string or an array with only one (1) item in it, the assets
682 * are returned as an indexed array of files. Otherwise, an associative array
683 * is returned keyed by the type.
685 * @deprecated Will be removed in a future release.
689 * $assets = bootstrap_get_cdn_assets($type, $provider, $theme);
692 * use Drupal\bootstrap\Bootstrap;
693 * $theme = Bootstrap::getTheme($theme);
695 * if ($provider = $theme->getProvider($provider)) {
696 * $assets = $provider->getAssets($type);
700 * @see \Drupal\bootstrap\Plugin\Provider\Custom::getAssets()
701 * @see \Drupal\bootstrap\Plugin\Provider\JsDelivr::getAssets()
702 * @see \Drupal\bootstrap\Plugin\Provider\ProviderBase::getAssets()
703 * @see \Drupal\bootstrap\Plugin\Provider\ProviderInterface::getAssets()
704 * @see \Drupal\bootstrap\Theme::getProvider()
705 * @see \Drupal\bootstrap\Bootstrap::getTheme()
707 function bootstrap_get_cdn_assets($type = NULL, $provider = NULL, $theme = NULL) {
708 Bootstrap::deprecated();
710 if ($provider = Bootstrap::getTheme($theme)->getProvider($provider)) {
711 $assets = $provider->getAssets($type);
717 * Return information from the .info file of a theme (and possible base themes).
719 * @param string $theme_key
720 * The machine name of the theme.
722 * The key name of the item to return from the .info file. This value can
723 * include "][" to automatically attempt to traverse any arrays.
724 * @param bool $base_themes
725 * Recursively search base themes, defaults to TRUE.
727 * @return string|array|false
728 * A string or array depending on the type of value and if a base theme also
729 * contains the same $key, FALSE if no $key is found.
731 * @deprecated Will be removed in a future release. There is no replacement.
733 function bootstrap_get_theme_info($theme_key = NULL, $key = NULL, $base_themes = TRUE) {
734 Bootstrap::deprecated();
735 // If no $theme_key is given, use the current theme if we can determine it.
736 if (!isset($theme_key)) {
737 $theme_key = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : FALSE;
740 $themes = \Drupal::service('theme_handler')->listInfo();
741 if (!empty($themes[$theme_key])) {
742 $theme = $themes[$theme_key];
743 // If a key name was specified, return just that array.
746 // Recursively add base theme values.
747 if ($base_themes && isset($theme->base_themes)) {
748 foreach (array_keys($theme->base_themes) as $base_theme) {
749 $value = bootstrap_get_theme_info($base_theme, $key);
752 if (!empty($themes[$theme_key])) {
753 $info = $themes[$theme_key]->info;
754 // Allow array traversal.
755 $keys = explode('][', $key);
756 foreach ($keys as $parent) {
757 if (isset($info[$parent])) {
758 $info = $info[$parent];
764 if (is_array($value)) {
766 if (!is_array($info)) {
769 $value = NestedArray::mergeDeep($value, $info);
778 if (!is_array($value)) {
781 if (!is_array($info)) {
784 $value = NestedArray::mergeDeep($value, $info);
791 // If no info $key was specified, just return the entire info array.
799 * Includes a file from a theme.
801 * @param string $theme
802 * Name of the theme to use for base path.
803 * @param string $path
804 * Path relative to $theme.
806 * @deprecated Will be removed in a future release.
810 * bootstrap_include('my_subtheme', 'includes/file.inc');
811 * bootstrap_include('my_subtheme', 'some/other/path/file.inc');
814 * use Drupal\bootstrap\Bootstrap;
815 * $my_subtheme = Bootstrap::getTheme('my_subtheme');
816 * $my_subtheme->includeOnce('file.inc');
817 * $my_subtheme->includeOnce('file.inc', 'some/other/path');
820 * @see \Drupal\bootstrap\Theme::includeOnce()
821 * @see \Drupal\bootstrap\Bootstrap::getTheme()
823 function bootstrap_include($theme, $path) {
824 Bootstrap::deprecated();
825 $theme = Bootstrap::getTheme($theme);
826 $parts = explode('/', $path);
827 $file = array_pop($parts);
828 $dir = implode('/', $parts);
829 $theme->includeOnce($file, $dir);
833 * Retrieves a setting for the current theme or for a given theme.
835 * @param string $name
836 * The name of the setting to be retrieved.
837 * @param string $theme
838 * The name of a given theme; defaults to the currently active theme.
839 * @param string $prefix
840 * The prefix used on the $name of the setting, this will be appended with
841 * "_" automatically if set.
844 * The value of the requested setting, NULL if the setting does not exist.
846 * @deprecated Will be removed in a future release.
849 * // Before ("button_colorize" and "my_subtheme_custom_option").
850 * $colorize = bootstrap_setting('button_colorize', 'my_subtheme');
851 * $custom_option = bootstrap_setting('custom_option', 'my_subtheme', 'my_subtheme');
853 * // After ("button_colorize" and "my_subtheme_custom_option").
854 * use Drupal\bootstrap\Bootstrap;
855 * $my_subtheme = Bootstrap::getTheme('my_subtheme');
856 * $my_subtheme->getSetting('button_colorize');
857 * $my_subtheme->getSetting('my_subtheme_custom_option');
860 * @see \Drupal\bootstrap\Theme::getSetting()
861 * @see \Drupal\bootstrap\Bootstrap::getTheme()
863 function bootstrap_setting($name, $theme = NULL, $prefix = 'bootstrap') {
864 Bootstrap::deprecated();
865 $theme = Bootstrap::getTheme($theme);
866 $prefix = $prefix !== 'bootstrap' && !empty($prefix) ? $prefix . '_' : '';
867 return $theme->getSetting($prefix . $name);