file bootstrap.api.php

  1. 8.x-3.x bootstrap.api.php
  2. 7.x-3.x bootstrap.api.php

List of available procedural hook and alter APIs for use in your sub-theme.

  1. <?php
  2. /**
  3. * @file
  4. * List of available procedural hook and alter APIs for use in your sub-theme.
  5. */
  6. /**
  7. * @addtogroup plugins_alter
  8. *
  9. * @{
  10. */
  11. /**
  12. * Allows sub-themes to alter the array used for colorizing text.
  13. *
  14. * @param array $texts
  15. * An associative array containing the text and classes to be matched, passed
  16. * by reference.
  17. *
  18. * @see \Drupal\bootstrap\Bootstrap::cssClassFromString()
  19. */
  20. function hook_bootstrap_colorize_text_alter(array &$texts) {
  21. // This matches the exact string: "My Unique Button Text".
  22. // Note: the t() function in D8 returns a TranslatableMarkup object.
  23. // It must be rendered to a string before it can be added as an array key.
  24. $texts['matches'][t('My Unique Button Text')->render()] = 'primary';
  25. // This would also match the string above, however the class returned would
  26. // also be the one above; "matches" takes precedence over "contains".
  27. $texts['contains'][t('Unique')->render()] = 'notice';
  28. // Remove matching for strings that contain "apply":
  29. unset($texts['contains'][t('Apply')->render()]);
  30. // Change the class that matches "Rebuild" (originally "warning"):
  31. $texts['contains'][t('Rebuild')->render()] = 'success';
  32. }
  33. /**
  34. * Allows sub-themes to alter the array used for associating an icon with text.
  35. *
  36. * @param array $texts
  37. * An associative array containing the text and icons to be matched, passed
  38. * by reference.
  39. *
  40. * @see \Drupal\bootstrap\Bootstrap::glyphiconFromString()
  41. */
  42. function hook_bootstrap_iconize_text_alter(array &$texts) {
  43. // This matches the exact string: "My Unique Button Text".
  44. // Note: the t() function in D8 returns a TranslatableMarkup object.
  45. // It must be rendered to a string before it can be added as an array key.
  46. $texts['matches'][t('My Unique Button Text')->render()] = 'heart';
  47. // This would also match the string above, however the class returned would
  48. // also be the one above; "matches" takes precedence over "contains".
  49. $texts['contains'][t('Unique')->render()] = 'bullhorn';
  50. // Remove matching for strings that contain "filter":
  51. unset($texts['contains'][t('Filter')->render()]);
  52. // Change the icon that matches "Upload" (originally "upload"):
  53. $texts['contains'][t('Upload')->render()] = 'ok';
  54. }
  55. /**
  56. * Allows sub-themes to alter element types that should be rendered as inline.
  57. *
  58. * @param array $types
  59. * The list of element types that should be rendered as inline.
  60. *
  61. * @deprecated in bootstrap:8.x-3.21 and is removed from bootstrap:8.x-4.0.
  62. * This method will be removed when process managers can be sub-classed.
  63. *
  64. * @see https://www.drupal.org/project/bootstrap/issues/2868538
  65. */
  66. function hook_bootstrap_inline_element_types_alter(array &$types) {
  67. // Remove certain types from the list.
  68. foreach (['number', 'tel'] as $type) {
  69. $index = array_search($type, $types);
  70. if ($index !== FALSE) {
  71. unset($types[$index]);
  72. }
  73. }
  74. }
  75. /**
  76. * Allows sub-themes to alter which element properties should be strings.
  77. *
  78. * Note: this only applies with using \Drupal\bootstrap\Utility\Element objects.
  79. * This is primarily used in cases where the value of the property in
  80. * question is only supported as an already rendered string and not a render
  81. * array (i.e. prefix/suffix) due to the limitations of upstream (core) code.
  82. * It should not be relied on as a way to "easily convert" properties to
  83. * strings to circumvent supporting OOP code.
  84. *
  85. * @param array $properties
  86. * An indexed array of property names, without the # prefix, passed by
  87. * reference.
  88. *
  89. * @see \Drupal\bootstrap\Utility\Element::isStringProperty
  90. */
  91. function hook_element_string_properties_alter(array &$properties) {
  92. // A contrib module property that should always be a string.
  93. $properties[] = 'contrib_module_property';
  94. }
  95. /**
  96. * @} End of "addtogroup".
  97. */

Functions

Name Description
hook_bootstrap_colorize_text_alter Allows sub-themes to alter the array used for colorizing text.
hook_bootstrap_iconize_text_alter Allows sub-themes to alter the array used for associating an icon with text.
hook_bootstrap_inline_element_types_alter Allows sub-themes to alter element types that should be rendered as inline.
hook_element_string_properties_alter Allows sub-themes to alter which element properties should be strings.