button.func.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_button().
  5. */
  6. /**
  7. * Returns HTML for a button form element.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - element: An associative array containing the properties of the element.
  12. * Properties used: #attributes, #button_type, #name, #value.
  13. *
  14. * @return string
  15. * The constructed HTML.
  16. *
  17. * @see theme_button()
  18. *
  19. * @ingroup theme_functions
  20. */
  21. function bootstrap_button($variables) {
  22. $element = $variables['element'];
  23. // Allow button text to be appear hidden.
  24. // @see https://www.drupal.org/node/2327437
  25. $text = !empty($element['#hide_text']) ? '<span class="element-invisible">' . $element['#value'] . '</span>' : $element['#value'];
  26. // Add icons before or after the value.
  27. // @see https://www.drupal.org/node/2219965
  28. if (!empty($element['#icon'])) {
  29. if ($element['#icon_position'] === 'before') {
  30. $text = $element['#icon'] . ' ' . $text;
  31. }
  32. elseif ($element['#icon_position'] === 'after') {
  33. $text .= ' ' . $element['#icon'];
  34. }
  35. }
  36. // This line break adds inherent margin between multiple buttons.
  37. return '<button' . drupal_attributes($element['#attributes']) . '>' . $text . "</button>\n";
  38. }