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 specific Bootstrap Glyphicon as a render array.
  336. *
  337. * Note: This function was added in 7.x-3.17 to keep BC with the former
  338. * _bootstrap_icon() implementation since it didn't return a render array. It
  339. * is basically a backport of 8.x-3.x code so the added $attributes parameter
  340. * can be more easily dealt with.
  341. *
  342. * @param string $name
  343. * The icon name, minus the "glyphicon-" prefix.
  344. * @param array|string $default
  345. * (Optional) The default render array to use if $name is not available.
  346. * @param array $attributes
  347. * (Optional) Additional attributes to merge onto the icon.
  348. *
  349. * @return array
  350. * The render containing the icon defined by $name, $default value if
  351. * icon does not exist or returns NULL if no icon could be rendered.
  352. *
  353. * @deprecated Will be removed in a future release.
  354. *
  355. * @code
  356. * // Before.
  357. * $icon = _bootstrap_glyphicon($name, $default, $attributes);
  358. *
  359. * // After.
  360. * use Drupal\bootstrap\Bootstrap;
  361. * use Drupal\bootstrap\Utility\Element;
  362. * $icon = Bootstrap::glyphicon($name, ['#markup' => $default]);
  363. * $icon_attributes = isset($icon['#attributes']) ? $icon['#attributes'] : [];
  364. * unset($icon['#attributes']);
  365. * $icon = Element::createStandalone($icon)->setAttributes($attributes)->setAttributes($icon_attributes)->getArray();
  366. * @endcode
  367. *
  368. * @see https://www.drupal.org/project/bootstrap/issues/2844885
  369. * @see \Drupal\bootstrap\Bootstrap::glyphicon()
  370. * @see \Drupal\bootstrap\Utility\Element::createStandalone()
  371. */
  372. function _bootstrap_glyphicon($name, $default = [], array $attributes = []) {
  373. Bootstrap::deprecated();
  374. $icon = Bootstrap::glyphicon($name, ['#markup' => $default]);
  375. $icon_attributes = isset($icon['#attributes']) ? $icon['#attributes'] : [];
  376. unset($icon['#attributes']);
  377. return Element::createStandalone($icon)->setAttributes($attributes)->setAttributes($icon_attributes)->getArray();
  378. }
  379. /**
  380. * Returns a list of available Bootstrap Glyphicons.
  381. *
  382. * @param string $version
  383. * The specific version of glyphicons to return. If not set, the latest
  384. * BOOTSTRAP_VERSION will be used.
  385. *
  386. * @return array
  387. * An associative array of icons keyed by their classes.
  388. *
  389. * @deprecated Will be removed in a future release.
  390. *
  391. * @code
  392. * // Before.
  393. * $glyphicons = _bootstrap_glyphicons($version);
  394. *
  395. * // After.
  396. * use Drupal\bootstrap\Bootstrap;
  397. * $glyphicons = Bootstrap::glyphicons($version);
  398. * @endcode
  399. *
  400. * @see \Drupal\bootstrap\Bootstrap::glyphicons()
  401. */
  402. function _bootstrap_glyphicons($version = NULL) {
  403. Bootstrap::deprecated();
  404. return Bootstrap::glyphicons($version);
  405. }
  406. /**
  407. * Determine whether or not Bootstrap Glyphicons can be used.
  408. *
  409. * @deprecated Will be removed in a future release.
  410. *
  411. * @code
  412. * // Before.
  413. * $supported = _bootstrap_glyphicons_supported();
  414. *
  415. * // After.
  416. * use Drupal\bootstrap\Bootstrap;
  417. * $theme = Bootstrap::getTheme();
  418. * $supported = $theme->hasGlyphicons();
  419. * @endcode
  420. *
  421. * @see \Drupal\bootstrap\Theme::hasGlyphicons()
  422. */
  423. function _bootstrap_glyphicons_supported() {
  424. Bootstrap::deprecated();
  425. return Bootstrap::getTheme()->hasGlyphicons();
  426. }
  427. /**
  428. * Returns a specific Bootstrap Glyphicon as rendered HTML markup.
  429. *
  430. * @param string $name
  431. * The icon name, minus the "glyphicon-" prefix.
  432. * @param string $default
  433. * (Optional) The default value to return.
  434. * @param array $attributes
  435. * (Optional) Additional attributes to merge onto the icon.
  436. *
  437. * @return string
  438. * The HTML markup containing the icon defined by $name, $default value if
  439. * icon does not exist or returns empty output for whatever reason.
  440. *
  441. * @deprecated Will be removed in a future release.
  442. *
  443. * @code
  444. * // Before.
  445. * $icon = _bootstrap_icon($name, $default, $attributes);
  446. *
  447. * // After.
  448. * use Drupal\bootstrap\Bootstrap;
  449. * use Drupal\bootstrap\Utility\Element;
  450. * $icon = Bootstrap::glyphicon($name, ['#markup' => $default]);
  451. * $icon_attributes = isset($icon['#attributes']) ? $icon['#attributes'] : [];
  452. * unset($icon['#attributes']);
  453. * $icon = (string) Element::createStandalone($icon)->setAttributes($attributes)->setAttributes($icon_attributes)->renderPlain();
  454. * @endcode
  455. *
  456. * @see \Drupal\bootstrap\Bootstrap::glyphicon()
  457. * @see \Drupal\bootstrap\Utility\Element::createStandalone()
  458. */
  459. function _bootstrap_icon($name, $default = NULL, array $attributes = []) {
  460. Bootstrap::deprecated();
  461. $icon = Bootstrap::glyphicon($name, ['#markup' => $default]);
  462. $icon_attributes = isset($icon['#attributes']) ? $icon['#attributes'] : [];
  463. unset($icon['#attributes']);
  464. return (string) Element::createStandalone($icon)->setAttributes($attributes)->setAttributes($icon_attributes)->renderPlain();
  465. }
  466. /**
  467. * Adds an icon to button element based on its text value.
  468. *
  469. * @param array $element
  470. * The form element, passed by reference.
  471. *
  472. * @deprecated Will be removed in a future release.
  473. *
  474. * @code
  475. * // Before.
  476. * _bootstrap_iconize_button($element);
  477. *
  478. * // After.
  479. * use Drupal\bootstrap\Utility\Element;
  480. * Element::create($element)->setIcon();
  481. * @endcode
  482. *
  483. * @see \Drupal\bootstrap\Utility\Element::setIcon()
  484. */
  485. function _bootstrap_iconize_button(array &$element) {
  486. Bootstrap::deprecated();
  487. Element::create($element)->setIcon();
  488. }
  489. /**
  490. * Matches a Bootstrap Glyphicon based on a string value.
  491. *
  492. * @param string $string
  493. * The string to match classes against.
  494. * @param string $default
  495. * The default icon to return if no match is found.
  496. *
  497. * @return string
  498. * The Bootstrap icon matched against the value of $haystack or $default if
  499. * no match could be made.
  500. *
  501. * @deprecated Will be removed in a future release.
  502. *
  503. * @code
  504. * // Before.
  505. * $icon = _bootstrap_iconize_text($string, $default);
  506. *
  507. * // After.
  508. * use Drupal\bootstrap\Bootstrap;
  509. * $icon = Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
  510. * @endcode
  511. *
  512. * @see \Drupal\bootstrap\Bootstrap::glyphiconFromString()
  513. */
  514. function _bootstrap_iconize_text($string, $default = '') {
  515. Bootstrap::deprecated();
  516. return Bootstrap::glyphiconFromString($string, ['#markup' => $default]);
  517. }
  518. /**
  519. * Determines if an element is a button.
  520. *
  521. * @param array $element
  522. * A render array element.
  523. *
  524. * @return bool
  525. * TRUE or FALSE.
  526. *
  527. * @deprecated Will be removed in a future release.
  528. *
  529. * @code
  530. * // Before.
  531. * $button = _bootstrap_is_button($element);
  532. *
  533. * // After.
  534. * use Drupal\bootstrap\Utility\Element;
  535. * $button = Element::create($element)->isButton();
  536. * @endcode
  537. *
  538. * @see \Drupal\bootstrap\Utility\Element::isButton()
  539. */
  540. function _bootstrap_is_button(array $element) {
  541. Bootstrap::deprecated();
  542. return Element::create($element)->isButton();
  543. }
  544. /**
  545. * Determines if a string of text is considered "simple".
  546. *
  547. * @param string $string
  548. * The string of text to check "simple" criteria on.
  549. * @param int|false $length
  550. * The length of characters used to determine whether or not $string is
  551. * considered "simple". Set explicitly to FALSE to disable this criteria.
  552. * @param array|false $allowed_tags
  553. * An array of allowed tag elements. Set explicitly to FALSE to disable this
  554. * criteria.
  555. * @param bool $html
  556. * A variable, passed by reference, that indicates whether or not the
  557. * string contains HTML.
  558. *
  559. * @return bool
  560. * Returns TRUE if the $string is considered "simple", FALSE otherwise.
  561. *
  562. * @deprecated Will be removed in a future release.
  563. *
  564. * @code
  565. * // Before.
  566. * $simple = _bootstrap_is_simple_string($string, $length, $allowed_tags, $html);
  567. *
  568. * // After.
  569. * use Drupal\bootstrap\Utility\Unicode;
  570. * $simple = Unicode::isSimple($string, $length, $allowed_tags, $html);
  571. * @endcode
  572. *
  573. * @see \Drupal\bootstrap\Utility\Unicode::isSimple()
  574. */
  575. function _bootstrap_is_simple_string($string, $length = 250, $allowed_tags = NULL, &$html = FALSE) {
  576. Bootstrap::deprecated();
  577. return Unicode::isSimple($string, $length, $allowed_tags, $html);
  578. }
  579. /**
  580. * Removes a class from an element's attributes array.
  581. *
  582. * @param string|array $class
  583. * An individual class or an array of classes to remove.
  584. * @param array $element
  585. * The individual renderable array element.
  586. * @param string $property
  587. * Determines which attributes array to retrieve. By default, this is the
  588. * element's normal "attributes", but it could also be one of the following:
  589. * - "content_attributes"
  590. * - "input_group_attributes"
  591. * - "title_attributes"
  592. * - "wrapper_attributes".
  593. *
  594. * @deprecated Will be removed in a future release.
  595. *
  596. * @code
  597. * // Before.
  598. * _bootstrap_remove_class('my-class', $element);
  599. *
  600. * // After.
  601. * use Drupal\bootstrap\Utility\Element;
  602. * Element::create($element)->removeClass('my-class');
  603. * @endcode
  604. *
  605. * @see \Drupal\bootstrap\Utility\Element::removeClass()
  606. */
  607. function _bootstrap_remove_class($class, array &$element, $property = 'attributes') {
  608. Bootstrap::deprecated();
  609. Element::create($element)->removeClass($class, $property);
  610. }
  611. /**
  612. * Retrieves a list of available CDN providers for the Bootstrap framework.
  613. *
  614. * @param string $provider
  615. * A specific provider data to return.
  616. * @param bool $reset
  617. * Toggle determining whether or not to reset the database cache.
  618. *
  619. * @return array|false
  620. * An associative array of CDN providers, keyed by their machine name if
  621. * $provider is not set. If $provider is set and exists, it's individual
  622. * data array will be returned. If $provider is set and the data does not
  623. * exist then FALSE will be returned.
  624. *
  625. * @deprecated Will be removed in a future release.
  626. *
  627. * @code
  628. * // Before.
  629. * $providers = bootstrap_cdn_provider();
  630. * $jsdelivr = bootstrap_cdn_provider('jsdelivr');
  631. *
  632. * // After.
  633. * use Drupal\bootstrap\Bootstrap;
  634. * use Drupal\bootstrap\Plugin\ProviderManager;
  635. *
  636. * $theme = Bootstrap::getTheme();
  637. *
  638. * // Get provider definitions, the "equivalent" for bootstrap_cdn_provider().
  639. * $provider_manager = new ProviderManager($theme);
  640. * $providers = $provider_manager->getDefinitions();
  641. * $jsdelivr = $provider_manager->getDefinition('jsdelivr');
  642. *
  643. * // You should, however, use the the fully initialized classes made
  644. * // available through a theme instance.
  645. * $providers = $theme->getProviders();
  646. * $jsdelivr = $theme->getProvider('jsdelivr');
  647. * @endcode
  648. *
  649. * @see \Drupal\bootstrap\Plugin\ProviderManager
  650. * @see \Drupal\bootstrap\Theme::getCdnProviders()
  651. * @see \Drupal\bootstrap\Theme::getCdnProvider()
  652. */
  653. function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) {
  654. Bootstrap::deprecated();
  655. $provider_manager = new ProviderManager(Bootstrap::getTheme());
  656. if ($reset) {
  657. $provider_manager->clearCachedDefinitions();
  658. }
  659. if (isset($provider)) {
  660. if ($provider_manager->hasDefinition($provider)) {
  661. return $provider_manager->getDefinition($provider);
  662. }
  663. return FALSE;
  664. }
  665. return $provider_manager->getDefinitions();
  666. }
  667. /**
  668. * Converts an element description into a tooltip based on certain criteria.
  669. *
  670. * @param array $element
  671. * An element render array, passed by reference.
  672. * @param array $target
  673. * The target element render array the tooltip is to be attached to, passed
  674. * by reference. If not set, it will default to the $element passed.
  675. * @param bool $input_only
  676. * Toggle determining whether or not to only convert input elements.
  677. * @param int $length
  678. * The length of characters to determine if description is "simple".
  679. *
  680. * @deprecated Will be removed in a future release.
  681. *
  682. * @code
  683. * // Before.
  684. * bootstrap_element_smart_description($element, $target, $input_only, $length);
  685. *
  686. * // After.
  687. * use Drupal\bootstrap\Utility\Element;
  688. * Element::create($element)->smartDescription($target, $input_only, $length);
  689. * @endcode
  690. *
  691. * @see \Drupal\bootstrap\Utility\Element::smartDescription()
  692. */
  693. function bootstrap_element_smart_description(array &$element, array &$target = NULL, $input_only = TRUE, $length = NULL) {
  694. Bootstrap::deprecated();
  695. Element::create($element)->smartDescription($target, $input_only, $length);
  696. }
  697. /**
  698. * Retrieves CDN assets for the active provider, if any.
  699. *
  700. * @param string|array $type
  701. * The type of asset to retrieve: "css" or "js", defaults to an array
  702. * array containing both if not set.
  703. * @param string $provider
  704. * The name of a specific CDN provider to use, defaults to the active provider
  705. * set in the theme settings.
  706. * @param string $theme
  707. * The name of a specific theme the settings should be retrieved from,
  708. * defaults to the active theme.
  709. *
  710. * @return array
  711. * If $type is a string or an array with only one (1) item in it, the assets
  712. * are returned as an indexed array of files. Otherwise, an associative array
  713. * is returned keyed by the type.
  714. *
  715. * @deprecated Will be removed in a future release.
  716. *
  717. * @code
  718. * // Before.
  719. * $assets = bootstrap_get_cdn_assets($type, $provider, $theme);
  720. *
  721. * // After.
  722. * use Drupal\bootstrap\Plugin\ProviderManager;
  723. * $original_type = $type;
  724. * $config = \Drupal::config('system.performance');
  725. * $cdnAssets = ProviderManager::load($theme, $provider)->getCdnAssets();
  726. * $data = [];
  727. * $types = !isset($type) ? ['css', 'js'] : (array) $type;
  728. * foreach ($types as $type) {
  729. * if ($config->get("$type.preprocess") && !empty($cdnAssets['min'][$type])) {
  730. * $data[$type] = $cdnAssets['min'][$type];
  731. * }
  732. * elseif (!empty($data[$type])) {
  733. * $data[$type] = $cdnAssets[$type];
  734. * }
  735. * }
  736. * $assets = is_string($original_type) ? $data[$original_type] : $data;
  737. * @endcode
  738. *
  739. * @see \Drupal\bootstrap\Plugin\Provider\Custom::getAssets()
  740. * @see \Drupal\bootstrap\Plugin\Provider\JsDelivr::getAssets()
  741. * @see \Drupal\bootstrap\Plugin\Provider\ProviderBase::getAssets()
  742. * @see \Drupal\bootstrap\Plugin\Provider\ProviderInterface::getAssets()
  743. * @see \Drupal\bootstrap\Plugin\ProviderManager::load()
  744. */
  745. function bootstrap_get_cdn_assets($type = NULL, $provider = NULL, $theme = NULL) {
  746. Bootstrap::deprecated();
  747. $original_type = $type;
  748. $return = [];
  749. $config = \Drupal::config('system.performance');
  750. $assets = ProviderManager::load($theme, $provider)->getCdnAssets();
  751. $types = !isset($type) ? ['css', 'js'] : (array) $type;
  752. foreach ($types as $type) {
  753. $return[$type] = $assets->get($type, $config->get("$type.preprocess"));
  754. }
  755. return is_string($original_type) ? $return[$original_type] : $return;
  756. }
  757. /**
  758. * Return information from the .info file of a theme (and possible base themes).
  759. *
  760. * @param string $theme_key
  761. * The machine name of the theme.
  762. * @param string $key
  763. * The key name of the item to return from the .info file. This value can
  764. * include "][" to automatically attempt to traverse any arrays.
  765. * @param bool $base_themes
  766. * Recursively search base themes, defaults to TRUE.
  767. *
  768. * @return string|array|false
  769. * A string or array depending on the type of value and if a base theme also
  770. * contains the same $key, FALSE if no $key is found.
  771. *
  772. * @deprecated Will be removed in a future release. There is no replacement.
  773. */
  774. function bootstrap_get_theme_info($theme_key = NULL, $key = NULL, $base_themes = TRUE) {
  775. Bootstrap::deprecated();
  776. // If no $theme_key is given, use the current theme if we can determine it.
  777. if (!isset($theme_key)) {
  778. $theme_key = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : FALSE;
  779. }
  780. if ($theme_key) {
  781. $themes = \Drupal::service('theme_handler')->listInfo();
  782. if (!empty($themes[$theme_key])) {
  783. $theme = $themes[$theme_key];
  784. // If a key name was specified, return just that array.
  785. if ($key) {
  786. $value = FALSE;
  787. // Recursively add base theme values.
  788. if ($base_themes && isset($theme->base_themes)) {
  789. foreach (array_keys($theme->base_themes) as $base_theme) {
  790. $value = bootstrap_get_theme_info($base_theme, $key);
  791. }
  792. }
  793. if (!empty($themes[$theme_key])) {
  794. $info = $themes[$theme_key]->info;
  795. // Allow array traversal.
  796. $keys = explode('][', $key);
  797. foreach ($keys as $parent) {
  798. if (isset($info[$parent])) {
  799. $info = $info[$parent];
  800. }
  801. else {
  802. $info = FALSE;
  803. }
  804. }
  805. if (is_array($value)) {
  806. if (!empty($info)) {
  807. if (!is_array($info)) {
  808. $info = [$info];
  809. }
  810. $value = NestedArray::mergeDeep($value, $info);
  811. }
  812. }
  813. else {
  814. if (!empty($info)) {
  815. if (empty($value)) {
  816. $value = $info;
  817. }
  818. else {
  819. if (!is_array($value)) {
  820. $value = [$value];
  821. }
  822. if (!is_array($info)) {
  823. $info = [$info];
  824. }
  825. $value = NestedArray::mergeDeep($value, $info);
  826. }
  827. }
  828. }
  829. }
  830. return $value;
  831. }
  832. // If no info $key was specified, just return the entire info array.
  833. return $theme->info;
  834. }
  835. }
  836. return FALSE;
  837. }
  838. /**
  839. * Includes a file from a theme.
  840. *
  841. * @param string $theme
  842. * Name of the theme to use for base path.
  843. * @param string $path
  844. * Path relative to $theme.
  845. *
  846. * @deprecated Will be removed in a future release.
  847. *
  848. * @code
  849. * // Before.
  850. * bootstrap_include('my_subtheme', 'includes/file.inc');
  851. * bootstrap_include('my_subtheme', 'some/other/path/file.inc');
  852. *
  853. * // After.
  854. * use Drupal\bootstrap\Bootstrap;
  855. * $my_subtheme = Bootstrap::getTheme('my_subtheme');
  856. * $my_subtheme->includeOnce('file.inc');
  857. * $my_subtheme->includeOnce('file.inc', 'some/other/path');
  858. * @endcode
  859. *
  860. * @see \Drupal\bootstrap\Theme::includeOnce()
  861. * @see \Drupal\bootstrap\Bootstrap::getTheme()
  862. */
  863. function bootstrap_include($theme, $path) {
  864. Bootstrap::deprecated();
  865. $theme = Bootstrap::getTheme($theme);
  866. $parts = explode('/', $path);
  867. $file = array_pop($parts);
  868. $dir = implode('/', $parts);
  869. $theme->includeOnce($file, $dir);
  870. }
  871. /**
  872. * Retrieves a setting for the current theme or for a given theme.
  873. *
  874. * @param string $name
  875. * The name of the setting to be retrieved.
  876. * @param string $theme
  877. * The name of a given theme; defaults to the currently active theme.
  878. * @param string $prefix
  879. * The prefix used on the $name of the setting, this will be appended with
  880. * "_" automatically if set.
  881. * @param mixed $default
  882. * The default value to return if setting doesn't exist or is not set.
  883. *
  884. * @return mixed
  885. * The value of the requested setting, NULL if the setting does not exist.
  886. *
  887. * @deprecated Will be removed in a future release.
  888. *
  889. * @code
  890. * // Before ("button_colorize" and "my_subtheme_custom_option").
  891. * $colorize = bootstrap_setting('button_colorize', 'my_subtheme');
  892. * $custom_option = bootstrap_setting('custom_option', 'my_subtheme', 'my_subtheme');
  893. *
  894. * // After ("button_colorize" and "my_subtheme_custom_option").
  895. * use Drupal\bootstrap\Bootstrap;
  896. * $my_subtheme = Bootstrap::getTheme('my_subtheme');
  897. * $my_subtheme->getSetting('button_colorize');
  898. * $my_subtheme->getSetting('my_subtheme_custom_option');
  899. * @endcode
  900. *
  901. * @see \Drupal\bootstrap\Theme::getSetting()
  902. * @see \Drupal\bootstrap\Bootstrap::getTheme()
  903. */
  904. function bootstrap_setting($name, $theme = NULL, $prefix = 'bootstrap', $default = NULL) {
  905. Bootstrap::deprecated();
  906. $theme = Bootstrap::getTheme($theme);
  907. $prefix = $prefix !== 'bootstrap' && !empty($prefix) ? $prefix . '_' : '';
  908. return $theme->getSetting($prefix . $name, $default);
  909. }

Functions

Name 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_glyphicon Returns a specific Bootstrap Glyphicon as a render 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 as rendered HTML markup.
_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

Name 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.