file deprecated.php

This contains deprecated functions that will be removed in a future release.

Source
  1. <?php
  2. /**
  3. * @file
  4. * This contains deprecated functions that will be removed in a future release.
  5. */
  6. use Drupal\bootstrap\Bootstrap;
  7. use Drupal\bootstrap\Plugin\ProviderManager;
  8. use Drupal\bootstrap\Utility\Element;
  9. use Drupal\bootstrap\Utility\Unicode;
  10. use Drupal\Component\Utility\NestedArray;
  11. /**
  12. * The base file system path for CDN providers.
  13. *
  14. * @deprecated Will be removed in a future release.
  15. *
  16. * @code
  17. * // Before.
  18. * echo BOOTSTRAP_CDN_PROVIDER_PATH;
  19. *
  20. * // After.
  21. * use Drupal\bootstrap\Plugin\ProviderManager;
  22. * echo ProviderManager::FILE_PATH;
  23. * @endcode
  24. *
  25. * @see \Drupal\bootstrap\Plugin\ProviderManager::FILE_PATH
  26. */
  27. define('BOOTSTRAP_CDN_PROVIDER_PATH', ProviderManager::FILE_PATH);
  28. /**
  29. * The current supported Bootstrap framework major version number.
  30. *
  31. * @deprecated Will be removed in a future release.
  32. *
  33. * @code
  34. * // Before.
  35. * echo BOOTSTRAP_VERSION_MAJOR;
  36. *
  37. * // After.
  38. * use Drupal\bootstrap\Bootstrap;
  39. * echo substr(Bootstrap::FRAMEWORK_VERSION, 0, 1);
  40. * @endcode
  41. *
  42. * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
  43. */
  44. define('BOOTSTRAP_VERSION_MAJOR', substr(Bootstrap::FRAMEWORK_VERSION, 0, 1));
  45. /**
  46. * The current supported Bootstrap framework minor version number.
  47. *
  48. * @deprecated Will be removed in a future release.
  49. *
  50. * @code
  51. * // Before.
  52. * echo BOOTSTRAP_VERSION_MINOR;
  53. *
  54. * // After.
  55. * use Drupal\bootstrap\Bootstrap;
  56. * echo substr(Bootstrap::FRAMEWORK_VERSION, 2, 1);
  57. * @endcode
  58. *
  59. * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
  60. */
  61. define('BOOTSTRAP_VERSION_MINOR', substr(Bootstrap::FRAMEWORK_VERSION, 2, 1));
  62. /**
  63. * The current supported Bootstrap framework patch version number.
  64. *
  65. * @deprecated Will be removed in a future release.
  66. *
  67. * @code
  68. * // Before.
  69. * echo BOOTSTRAP_VERSION_PATCH;
  70. *
  71. * // After.
  72. * use Drupal\bootstrap\Bootstrap;
  73. * echo substr(Bootstrap::FRAMEWORK_VERSION, 4, 1);
  74. * @endcode
  75. *
  76. * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
  77. */
  78. define('BOOTSTRAP_VERSION_PATCH', substr(Bootstrap::FRAMEWORK_VERSION, 4, 1));
  79. /**
  80. * The current supported Bootstrap framework version.
  81. *
  82. * @deprecated Will be removed in a future release.
  83. *
  84. * @code
  85. * // Before.
  86. * echo BOOTSTRAP_VERSION;
  87. *
  88. * // After.
  89. * use Drupal\bootstrap\Bootstrap;
  90. * echo Bootstrap::FRAMEWORK_VERSION;
  91. * @endcode
  92. *
  93. * @see \Drupal\bootstrap\Bootstrap::FRAMEWORK_VERSION
  94. */
  95. define('BOOTSTRAP_VERSION', Bootstrap::FRAMEWORK_VERSION);
  96. /**
  97. * Adds a class to an element's render array.
  98. *
  99. * @param string|array $class
  100. * An individual class or an array of classes to add.
  101. * @param array $element
  102. * The individual renderable array element. It is possible to also pass the
  103. * $variables parameter in [pre]process functions and it will logically
  104. * determine the correct path to that particular theme hook's classes array.
  105. * Passed by reference.
  106. * @param string $property
  107. * Determines which attributes array to retrieve. By default, this is the
  108. * element's normal "attributes", but it could also be one of the following:
  109. * - "content_attributes"
  110. * - "input_group_attributes"
  111. * - "title_attributes"
  112. * - "wrapper_attributes".
  113. *
  114. * @deprecated Will be removed in a future release.
  115. *
  116. * @code
  117. * // Before.
  118. * _bootstrap_add_class('my-class', $element);
  119. *
  120. * // After.
  121. * use Drupal\bootstrap\Utility\Element;
  122. * Element::create($element)->addClass('my-class');
  123. * @endcode
  124. *
  125. * @see \Drupal\bootstrap\Utility\Element::addClass()
  126. */
  127. function _bootstrap_add_class($class, array &$element, $property = 'attributes') {
  128. Bootstrap::deprecated();
  129. Element::create($element)->addClass($class, $property);
  130. }
  131. /**
  132. * Adds a specific Bootstrap class to color a button based on its text value.
  133. *
  134. * @param array $element
  135. * The form element, passed by reference.
  136. *
  137. * @deprecated Will be removed in a future release.
  138. *
  139. * @code
  140. * // Before.
  141. * _bootstrap_colorize_button($element);
  142. *
  143. * // After.
  144. * use Drupal\bootstrap\Utility\Element;
  145. * Element::create($element)->colorize();
  146. * @endcode
  147. *
  148. * @see \Drupal\bootstrap\Utility\Element::colorize()
  149. * */
  150. function _bootstrap_colorize_button(array &$element) {
  151. Bootstrap::deprecated();
  152. Element::create($element)->colorize();
  153. }
  154. /**
  155. * Matches a Bootstrap class based on a string value.
  156. *
  157. * @param string $string
  158. * The string to match classes against.
  159. * @param string $default
  160. * The default class to return if no match is found.
  161. *
  162. * @return string
  163. * The Bootstrap class matched against the value of $haystack or $default if
  164. * no match could be made.
  165. *
  166. * @deprecated Will be removed in a future release.
  167. *
  168. * @code
  169. * // Before.
  170. * $class = _bootstrap_colorize_text($string, $default);
  171. *
  172. * // After.
  173. * use Drupal\bootstrap\Bootstrap;
  174. * $class = Bootstrap::cssClassFromString($string, $default);
  175. * @endcode
  176. *
  177. * @see \Drupal\bootstrap\Bootstrap::cssClassFromString()
  178. */
  179. function _bootstrap_colorize_text($string, $default = '') {
  180. Bootstrap::deprecated();
  181. return Bootstrap::cssClassFromString($string, $default);
  182. }
  183. /**
  184. * Wrapper for the core file_scan_directory() function.
  185. *
  186. * Finds all files that match a given mask in a given directory and then caches
  187. * the results. A general site cache clear will force new scans to be initiated
  188. * for already cached directories.
  189. *
  190. * @param string $dir
  191. * The base directory or URI to scan, without trailing slash.
  192. * @param string $mask
  193. * The preg_match() regular expression of the files to find.
  194. * @param array $options
  195. * Additional options to pass to file_scan_directory().
  196. *
  197. * @return array
  198. * An associative array (keyed on the chosen key) of objects with 'uri',
  199. * 'filename', and 'name' members corresponding to the matching files.
  200. *
  201. * @deprecated Will be removed in a future release.
  202. *
  203. * @code
  204. * // Before.
  205. * $files = _bootstrap_file_scan_directory($theme_path . '/js', '/\.js$/');
  206. *
  207. * // After.
  208. * use Drupal\bootstrap\Bootstrap;
  209. * $files = Bootstrap::getTheme()->fileScan('/\.js$/', 'js');
  210. * @endcode
  211. *
  212. * @see \Drupal\bootstrap\Theme::fileScan()
  213. * @see file_scan_directory()
  214. */
  215. function _bootstrap_file_scan_directory($dir, $mask, array $options = []) {
  216. Bootstrap::deprecated();
  217. $theme = Bootstrap::getTheme();
  218. $dir = preg_replace('/^' . preg_quote($theme->getPath()) . '\//', '', $dir);
  219. return $theme->fileScan($mask, $dir, $options);
  220. }
  221. /**
  222. * Retrieves an element's "attributes" array.
  223. *
  224. * @param array $element
  225. * The individual renderable array element, passed by reference.
  226. * @param string $property
  227. * Determines which attributes array to retrieve. By default, this is the
  228. * element's normal "attributes", but it could also be one of the following:
  229. * - "content_attributes"
  230. * - "input_group_attributes"
  231. * - "title_attributes"
  232. * - "wrapper_attributes".
  233. *
  234. * @return array
  235. * The attributes array.
  236. *
  237. * @deprecated Will be removed in a future release.
  238. *
  239. * @code
  240. * // Before.
  241. * $attributes = &_bootstrap_get_attributes($element);
  242. * $attributes['class'][] = 'my-class';
  243. *
  244. * // After.
  245. * use Drupal\bootstrap\Utility\Element;
  246. * $attributes = &Element::create($element)->getAttributes();
  247. * $attributes['class'][] = 'my-class';
  248. * @endcode
  249. *
  250. * @see \Drupal\bootstrap\Utility\Element::getAttributes()
  251. */
  252. function &_bootstrap_get_attributes(array &$element, $property = 'attributes') {
  253. Bootstrap::deprecated();
  254. return Element::create($element)->getAttributes($property);
  255. }
  256. /**
  257. * Returns a list of base themes for active or provided theme.
  258. *
  259. * @param string $theme_key
  260. * The machine name of the theme to check, if not set the active theme name
  261. * will be used.
  262. * @param bool $include_theme_key
  263. * Whether to append the returned list with $theme_key.
  264. *
  265. * @return array
  266. * An indexed array of base themes.
  267. *
  268. * @deprecated Will be removed in a future release.
  269. *
  270. * @code
  271. * // Before (including active theme).
  272. * $base_themes = _bootstrap_get_base_themes(NULL, TRUE);
  273. *
  274. * // Before (excluding active theme).
  275. * $base_themes = _bootstrap_get_base_themes('my_subtheme');
  276. *
  277. * // After (including active theme).
  278. * use Drupal\bootstrap\Bootstrap;
  279. * $theme = Bootstrap::getTheme();
  280. * $base_themes = array_keys($theme->getAncestry());
  281. *
  282. * // After (excluding active theme).
  283. * use Drupal\bootstrap\Bootstrap;
  284. * $my_subtheme = Bootstrap::getTheme('my_subtheme');
  285. * $base_themes = array_keys($my_subtheme->getAncestry());
  286. * array_pop($base_themes);
  287. * @endcode
  288. *
  289. * @see \Drupal\bootstrap\Theme::getAncestry()
  290. */
  291. function _bootstrap_get_base_themes($theme_key = NULL, $include_theme_key = FALSE) {
  292. Bootstrap::deprecated();
  293. $themes = array_keys(Bootstrap::getTheme($theme_key)->getAncestry());
  294. if (!$include_theme_key) {
  295. array_pop($themes);
  296. }
  297. return $themes;
  298. }
  299. /**
  300. * Retrieves an element's "class" attribute array.
  301. *
  302. * @param array $element
  303. * The individual renderable array element, passed by reference.
  304. * @param string $property
  305. * Determines which attributes array to retrieve. By default, this is the
  306. * element's normal "attributes", but it could also be one of the following:
  307. * - "content_attributes"
  308. * - "input_group_attributes"
  309. * - "title_attributes"
  310. * - "wrapper_attributes".
  311. *
  312. * @return array
  313. * The classes array.
  314. *
  315. * @deprecated Will be removed in a future release. There is no replacement.
  316. *
  317. * @code
  318. * // Before.
  319. * $classes = &_bootstrap_get_classes($element);
  320. * $classes[] = 'my-class';
  321. *
  322. * // After.
  323. * use Drupal\bootstrap\Utility\Element;
  324. * $classes = &Element::create($element)->getClasses();
  325. * $classes[] = 'my-class';
  326. * @endcode
  327. *
  328. * @see \Drupal\bootstrap\Utility\Element::getClasses()
  329. */
  330. function &_bootstrap_get_classes(array &$element, $property = 'attributes') {
  331. Bootstrap::deprecated();
  332. return Element::create($element)->getClasses($property);
  333. }
  334. /**
  335. * Returns a list of available Bootstrap Glyphicons.
  336. *
  337. * @param string $version
  338. * The specific version of glyphicons to return. If not set, the latest
  339. * BOOTSTRAP_VERSION will be used.
  340. *
  341. * @return array
  342. * An associative array of icons keyed by their classes.
  343. *
  344. * @deprecated Will be removed in a future release.
  345. *
  346. * @code
  347. * // Before.
  348. * $glyphicons = _bootstrap_glyphicons($version);
  349. *
  350. * // After.
  351. * use Drupal\bootstrap\Bootstrap;
  352. * $glyphicons = Bootstrap::glyphicons($version);
  353. * @endcode
  354. *
  355. * @see \Drupal\bootstrap\Bootstrap::glyphicons()
  356. */
  357. function _bootstrap_glyphicons($version = NULL) {
  358. Bootstrap::deprecated();
  359. return Bootstrap::glyphicons($version);
  360. }
  361. /**
  362. * Determine whether or not Bootstrap Glyphicons can be used.
  363. *
  364. * @deprecated Will be removed in a future release.
  365. *
  366. * @code
  367. * // Before.
  368. * $supported = _bootstrap_glyphicons_supported();
  369. *
  370. * // After.
  371. * use Drupal\bootstrap\Bootstrap;
  372. * $theme = Bootstrap::getTheme();
  373. * $supported = $theme->hasGlyphicons();
  374. * @endcode
  375. *
  376. * @see \Drupal\bootstrap\Theme::hasGlyphicons()
  377. */
  378. function _bootstrap_glyphicons_supported() {
  379. Bootstrap::deprecated();
  380. return Bootstrap::getTheme()->hasGlyphicons();
  381. }
  382. /**
  383. * Returns a specific Bootstrap Glyphicon.
  384. *
  385. * @param string $name
  386. * The icon name, minus the "glyphicon-" prefix.
  387. * @param string $default
  388. * (Optional) The default value to return.
  389. *
  390. * @return string
  391. * The HTML markup containing the icon defined by $name, $default value if
  392. * icon does not exist or returns empty output for whatever reason.
  393. *
  394. * @deprecated Will be removed in a future release.
  395. *
  396. * @code
  397. * // Before.
  398. * $icon = _bootstrap_icon($name, $default);
  399. *
  400. * // After.
  401. * use Drupal\bootstrap\Bootstrap;
  402. * use Drupal\bootstrap\Utility\Element;
  403. * $icon = (string) Element::createStandalone(Bootstrap::glyphicon($name, ['#markup' => $default]))->renderPlain();
  404. * @endcode
  405. *
  406. * @see \Drupal\bootstrap\Bootstrap::glyphicon()
  407. */
  408. function _bootstrap_icon($name, $default = NULL) {
  409. Bootstrap::deprecated();
  410. return Element::createStandalone(Bootstrap::glyphicon($name, ['#markup' => $default]))->renderPlain();
  411. }
  412. /**
  413. * Adds an icon to button element based on its text value.
  414. *
  415. * @param array $element
  416. * The form element, passed by reference.
  417. *
  418. * @deprecated Will be removed in a future release.
  419. *
  420. * @code
  421. * // Before.
  422. * _bootstrap_iconize_button($element);
  423. *
  424. * // After.
  425. * use Drupal\bootstrap\Utility\Element;
  426. * Element::create($element)->setIcon();
  427. * @endcode
  428. *
  429. * @see \Drupal\bootstrap\Utility\Element::setIcon()
  430. */
  431. function _bootstrap_iconize_button(array &$element) {
  432. Bootstrap::deprecated();
  433. Element::create($element)->setIcon();
  434. }
  435. /**
  436. * Matches a Bootstrap Glyphicon based on a string value.
  437. *
  438. * @param string $string
  439. * The string to match classes against.
  440. * @param string $default
  441. * The default icon to return if no match is found.
  442. *
  443. * @return string
  444. * The Bootstrap icon matched against the value of $haystack or $default if
  445. * no match could be made.
  446. *
  447. * @deprecated Will be removed in a future release.
  448. *
  449. * @code
  450. * // Before.
  451. * $icon = _bootstrap_iconize_text($string, $default);
  452. *
  453. * // After.
  454. * use Drupal\bootstrap\Bootstrap;
  455. * $icon = Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
  456. * @endcode
  457. *
  458. * @see \Drupal\bootstrap\Bootstrap::glyphiconFromString()
  459. */
  460. function _bootstrap_iconize_text($string, $default = '') {
  461. Bootstrap::deprecated();
  462. return Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
  463. }
  464. /**
  465. * Determines if an element is a button.
  466. *
  467. * @param array $element
  468. * A render array element.
  469. *
  470. * @return bool
  471. * TRUE or FALSE.
  472. *
  473. * @deprecated Will be removed in a future release.
  474. *
  475. * @code
  476. * // Before.
  477. * $button = _bootstrap_is_button($element);
  478. *
  479. * // After.
  480. * use Drupal\bootstrap\Utility\Element;
  481. * $button = Element::create($element)->isButton();
  482. * @endcode
  483. *
  484. * @see \Drupal\bootstrap\Utility\Element::isButton()
  485. */
  486. function _bootstrap_is_button(array $element) {
  487. Bootstrap::deprecated();
  488. return Element::create($element)->isButton();
  489. }
  490. /**
  491. * Determines if a string of text is considered "simple".
  492. *
  493. * @param string $string
  494. * The string of text to check "simple" criteria on.
  495. * @param int|FALSE $length
  496. * The length of characters used to determine whether or not $string is
  497. * considered "simple". Set explicitly to FALSE to disable this criteria.
  498. * @param array|FALSE $allowed_tags
  499. * An array of allowed tag elements. Set explicitly to FALSE to disable this
  500. * criteria.
  501. * @param bool $html
  502. * A variable, passed by reference, that indicates whether or not the
  503. * string contains HTML.
  504. *
  505. * @return bool
  506. * Returns TRUE if the $string is considered "simple", FALSE otherwise.
  507. *
  508. * @deprecated Will be removed in a future release.
  509. *
  510. * @code
  511. * // Before.
  512. * $simple = _bootstrap_is_simple_string($string, $length, $allowed_tags, $html);
  513. *
  514. * // After.
  515. * use Drupal\bootstrap\Utility\Unicode;
  516. * $simple = Unicode::isSimple($string, $length, $allowed_tags, $html);
  517. * @endcode
  518. *
  519. * @see \Drupal\bootstrap\Utility\Unicode::isSimple()
  520. */
  521. function _bootstrap_is_simple_string($string, $length = 250, $allowed_tags = NULL, &$html = FALSE) {
  522. Bootstrap::deprecated();
  523. return Unicode::isSimple($string, $length, $allowed_tags, $html);
  524. }
  525. /**
  526. * Removes a class from an element's attributes array.
  527. *
  528. * @param string|array $class
  529. * An individual class or an array of classes to remove.
  530. * @param array $element
  531. * The individual renderable array element.
  532. * @param string $property
  533. * Determines which attributes array to retrieve. By default, this is the
  534. * element's normal "attributes", but it could also be one of the following:
  535. * - "content_attributes"
  536. * - "input_group_attributes"
  537. * - "title_attributes"
  538. * - "wrapper_attributes".
  539. *
  540. * @deprecated Will be removed in a future release.
  541. *
  542. * @code
  543. * // Before.
  544. * _bootstrap_remove_class('my-class', $element);
  545. *
  546. * // After.
  547. * use Drupal\bootstrap\Utility\Element;
  548. * Element::create($element)->removeClass('my-class');
  549. * @endcode
  550. *
  551. * @see \Drupal\bootstrap\Utility\Element::removeClass()
  552. */
  553. function _bootstrap_remove_class($class, array &$element, $property = 'attributes') {
  554. Bootstrap::deprecated();
  555. Element::create($element)->removeClass($class, $property);
  556. }
  557. /**
  558. * Retrieves a list of available CDN providers for the Bootstrap framework.
  559. *
  560. * @param string $provider
  561. * A specific provider data to return.
  562. * @param bool $reset
  563. * Toggle determining whether or not to reset the database cache.
  564. *
  565. * @return array|FALSE
  566. * An associative array of CDN providers, keyed by their machine name if
  567. * $provider is not set. If $provider is set and exists, it's individual
  568. * data array will be returned. If $provider is set and the data does not
  569. * exist then FALSE will be returned.
  570. *
  571. * @deprecated Will be removed in a future release.
  572. *
  573. * @code
  574. * // Before.
  575. * $providers = bootstrap_cdn_provider();
  576. * $jsdelivr = bootstrap_cdn_provider('jsdelivr');
  577. *
  578. * // After.
  579. * use Drupal\bootstrap\Bootstrap;
  580. * use Drupal\bootstrap\Plugin\ProviderManager;
  581. *
  582. * $theme = Bootstrap::getTheme();
  583. *
  584. * // Get provider definitions, the "equivalent" for bootstrap_cdn_provider().
  585. * $provider_manager = new ProviderManager($theme);
  586. * $providers = $provider_manager->getDefinitions();
  587. * $jsdelivr = $provider_manager->getDefinition('jsdelivr');
  588. *
  589. * // You should, however, use the the fully initialized classes made
  590. * // available through a theme instance.
  591. * $providers = $theme->getProviders();
  592. * $jsdelivr = $theme->getProvider('jsdelivr');
  593. * @endcode
  594. *
  595. * @see \Drupal\bootstrap\Plugin\ProviderManager
  596. * @see \Drupal\bootstrap\Theme::getProviders()
  597. * @see \Drupal\bootstrap\Theme::getProvider()
  598. */
  599. function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) {
  600. Bootstrap::deprecated();
  601. $provider_manager = new ProviderManager(Bootstrap::getTheme());
  602. if ($reset) {
  603. $provider_manager->clearCachedDefinitions();
  604. }
  605. if (isset($provider)) {
  606. if ($provider_manager->hasDefinition($provider)) {
  607. return $provider_manager->getDefinition($provider);
  608. }
  609. return FALSE;
  610. }
  611. return $provider_manager->getDefinitions();
  612. }
  613. /**
  614. * Converts an element description into a tooltip based on certain criteria.
  615. *
  616. * @param array $element
  617. * An element render array, passed by reference.
  618. * @param array $target
  619. * The target element render array the tooltip is to be attached to, passed
  620. * by reference. If not set, it will default to the $element passed.
  621. * @param bool $input_only
  622. * Toggle determining whether or not to only convert input elements.
  623. * @param int $length
  624. * The length of characters to determine if description is "simple".
  625. *
  626. * @deprecated Will be removed in a future release.
  627. *
  628. * @code
  629. * // Before.
  630. * bootstrap_element_smart_description($element, $target, $input_only, $length);
  631. *
  632. * // After.
  633. * use Drupal\bootstrap\Utility\Element;
  634. * Element::create($element)->smartDescription($target, $input_only, $length);
  635. * @endcode
  636. *
  637. * @see \Drupal\bootstrap\Utility\Element::smartDescription()
  638. */
  639. function bootstrap_element_smart_description(array &$element, array &$target = NULL, $input_only = TRUE, $length = NULL) {
  640. Bootstrap::deprecated();
  641. Element::create($element)->smartDescription($target, $input_only, $length);
  642. }
  643. /**
  644. * Retrieves CDN assets for the active provider, if any.
  645. *
  646. * @param string|array $type
  647. * The type of asset to retrieve: "css" or "js", defaults to an array
  648. * array containing both if not set.
  649. * @param string $provider
  650. * The name of a specific CDN provider to use, defaults to the active provider
  651. * set in the theme settings.
  652. * @param string $theme
  653. * The name of a specific theme the settings should be retrieved from,
  654. * defaults to the active theme.
  655. *
  656. * @return array
  657. * If $type is a string or an array with only one (1) item in it, the assets
  658. * are returned as an indexed array of files. Otherwise, an associative array
  659. * is returned keyed by the type.
  660. *
  661. * @deprecated Will be removed in a future release.
  662. *
  663. * @code
  664. * // Before.
  665. * $assets = bootstrap_get_cdn_assets($type, $provider, $theme);
  666. *
  667. * // After.
  668. * use Drupal\bootstrap\Bootstrap;
  669. * $theme = Bootstrap::getTheme($theme);
  670. * $assets = [];
  671. * if ($provider = $theme->getProvider($provider)) {
  672. * $assets = $provider->getAssets($type);
  673. * }
  674. * @endcode
  675. *
  676. * @see \Drupal\bootstrap\Plugin\Provider\Custom::getAssets()
  677. * @see \Drupal\bootstrap\Plugin\Provider\JsDelivr::getAssets()
  678. * @see \Drupal\bootstrap\Plugin\Provider\ProviderBase::getAssets()
  679. * @see \Drupal\bootstrap\Plugin\Provider\ProviderInterface::getAssets()
  680. * @see \Drupal\bootstrap\Theme::getProvider()
  681. * @see \Drupal\bootstrap\Bootstrap::getTheme()
  682. */
  683. function bootstrap_get_cdn_assets($type = NULL, $provider = NULL, $theme = NULL) {
  684. Bootstrap::deprecated();
  685. $assets = [];
  686. if ($provider = Bootstrap::getTheme($theme)->getProvider($provider)) {
  687. $assets = $provider->getAssets($type);
  688. }
  689. return $assets;
  690. }
  691. /**
  692. * Return information from the .info file of a theme (and possible base themes).
  693. *
  694. * @param string $theme_key
  695. * The machine name of the theme.
  696. * @param string $key
  697. * The key name of the item to return from the .info file. This value can
  698. * include "][" to automatically attempt to traverse any arrays.
  699. * @param bool $base_themes
  700. * Recursively search base themes, defaults to TRUE.
  701. *
  702. * @return string|array|false
  703. * A string or array depending on the type of value and if a base theme also
  704. * contains the same $key, FALSE if no $key is found.
  705. *
  706. * @deprecated Will be removed in a future release. There is no replacement.
  707. */
  708. function bootstrap_get_theme_info($theme_key = NULL, $key = NULL, $base_themes = TRUE) {
  709. Bootstrap::deprecated();
  710. // If no $theme_key is given, use the current theme if we can determine it.
  711. if (!isset($theme_key)) {
  712. $theme_key = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : FALSE;
  713. }
  714. if ($theme_key) {
  715. $themes = \Drupal::service('theme_handler')->listInfo();
  716. if (!empty($themes[$theme_key])) {
  717. $theme = $themes[$theme_key];
  718. // If a key name was specified, return just that array.
  719. if ($key) {
  720. $value = FALSE;
  721. // Recursively add base theme values.
  722. if ($base_themes && isset($theme->base_themes)) {
  723. foreach (array_keys($theme->base_themes) as $base_theme) {
  724. $value = bootstrap_get_theme_info($base_theme, $key);
  725. }
  726. }
  727. if (!empty($themes[$theme_key])) {
  728. $info = $themes[$theme_key]->info;
  729. // Allow array traversal.
  730. $keys = explode('][', $key);
  731. foreach ($keys as $parent) {
  732. if (isset($info[$parent])) {
  733. $info = $info[$parent];
  734. }
  735. else {
  736. $info = FALSE;
  737. }
  738. }
  739. if (is_array($value)) {
  740. if (!empty($info)) {
  741. if (!is_array($info)) {
  742. $info = [$info];
  743. }
  744. $value = NestedArray::mergeDeep($value, $info);
  745. }
  746. }
  747. else {
  748. if (!empty($info)) {
  749. if (empty($value)) {
  750. $value = $info;
  751. }
  752. else {
  753. if (!is_array($value)) {
  754. $value = [$value];
  755. }
  756. if (!is_array($info)) {
  757. $info = [$info];
  758. }
  759. $value = NestedArray::mergeDeep($value, $info);
  760. }
  761. }
  762. }
  763. }
  764. return $value;
  765. }
  766. // If no info $key was specified, just return the entire info array.
  767. return $theme->info;
  768. }
  769. }
  770. return FALSE;
  771. }
  772. /**
  773. * Includes a file from a theme.
  774. *
  775. * @param string $theme
  776. * Name of the theme to use for base path.
  777. * @param string $path
  778. * Path relative to $theme.
  779. *
  780. * @deprecated Will be removed in a future release.
  781. *
  782. * @code
  783. * // Before.
  784. * bootstrap_include('my_subtheme', 'includes/file.inc');
  785. * bootstrap_include('my_subtheme', 'some/other/path/file.inc');
  786. *
  787. * // After.
  788. * use Drupal\bootstrap\Bootstrap;
  789. * $my_subtheme = Bootstrap::getTheme('my_subtheme');
  790. * $my_subtheme->includeOnce('file.inc');
  791. * $my_subtheme->includeOnce('file.inc', 'some/other/path');
  792. * @endcode
  793. *
  794. * @see \Drupal\bootstrap\Theme::includeOnce()
  795. * @see \Drupal\bootstrap\Bootstrap::getTheme()
  796. */
  797. function bootstrap_include($theme, $path) {
  798. Bootstrap::deprecated();
  799. $theme = Bootstrap::getTheme($theme);
  800. $parts = explode('/', $path);
  801. $file = array_pop($parts);
  802. $dir = implode('/', $parts);
  803. $theme->includeOnce($file, $dir);
  804. }
  805. /**
  806. * Retrieves a setting for the current theme or for a given theme.
  807. *
  808. * @param string $name
  809. * The name of the setting to be retrieved.
  810. * @param string $theme
  811. * The name of a given theme; defaults to the currently active theme.
  812. * @param string $prefix
  813. * The prefix used on the $name of the setting, this will be appended with
  814. * "_" automatically if set.
  815. *
  816. * @return mixed
  817. * The value of the requested setting, NULL if the setting does not exist.
  818. *
  819. * @deprecated Will be removed in a future release.
  820. *
  821. * @code
  822. * // Before ("button_colorize" and "my_subtheme_custom_option").
  823. * $colorize = bootstrap_setting('button_colorize', 'my_subtheme');
  824. * $custom_option = bootstrap_setting('custom_option', 'my_subtheme', 'my_subtheme');
  825. *
  826. * // After ("button_colorize" and "my_subtheme_custom_option").
  827. * use Drupal\bootstrap\Bootstrap;
  828. * $my_subtheme = Bootstrap::getTheme('my_subtheme');
  829. * $my_subtheme->getSetting('button_colorize');
  830. * $my_subtheme->getSetting('my_subtheme_custom_option');
  831. * @endcode
  832. *
  833. * @see \Drupal\bootstrap\Theme::getSetting()
  834. * @see \Drupal\bootstrap\Bootstrap::getTheme()
  835. */
  836. function bootstrap_setting($name, $theme = NULL, $prefix = 'bootstrap') {
  837. Bootstrap::deprecated();
  838. $theme = Bootstrap::getTheme($theme);
  839. $prefix = $prefix !== 'bootstrap' && !empty($prefix) ? $prefix . '_' : '';
  840. return $theme->getSetting($prefix . $name);
  841. }

Functions

Namesort descending Description
bootstrap_cdn_provider Retrieves a list of available CDN providers for the Bootstrap framework.
bootstrap_element_smart_description Converts an element description into a tooltip based on certain criteria.
bootstrap_get_cdn_assets Retrieves CDN assets for the active provider, if any.
bootstrap_get_theme_info Return information from the .info file of a theme (and possible base themes).
bootstrap_include Includes a file from a theme.
bootstrap_setting Retrieves a setting for the current theme or for a given theme.
_bootstrap_add_class Adds a class to an element's render array.
_bootstrap_colorize_button Adds a specific Bootstrap class to color a button based on its text value.
_bootstrap_colorize_text Matches a Bootstrap class based on a string value.
_bootstrap_file_scan_directory Wrapper for the core file_scan_directory() function.
_bootstrap_get_attributes Retrieves an element's "attributes" array.
_bootstrap_get_base_themes Returns a list of base themes for active or provided theme.
_bootstrap_get_classes Retrieves an element's "class" attribute array.
_bootstrap_glyphicons Returns a list of available Bootstrap Glyphicons.
_bootstrap_glyphicons_supported Determine whether or not Bootstrap Glyphicons can be used.
_bootstrap_icon Returns a specific Bootstrap Glyphicon.
_bootstrap_iconize_button Adds an icon to button element based on its text value.
_bootstrap_iconize_text Matches a Bootstrap Glyphicon based on a string value.
_bootstrap_is_button Determines if an element is a button.
_bootstrap_is_simple_string Determines if a string of text is considered "simple".
_bootstrap_remove_class Removes a class from an element's attributes array.

Constants

Namesort descending Description
BOOTSTRAP_CDN_PROVIDER_PATH The base file system path for CDN providers.
BOOTSTRAP_VERSION The current supported Bootstrap framework version.
BOOTSTRAP_VERSION_MAJOR The current supported Bootstrap framework major version number.
BOOTSTRAP_VERSION_MINOR The current supported Bootstrap framework minor version number.
BOOTSTRAP_VERSION_PATCH The current supported Bootstrap framework patch version number.