process.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @file
  4. * process.inc
  5. *
  6. * Contains various implementations for #process callbacks on elements.
  7. */
  8. /**
  9. * Implements hook_form_process().
  10. */
  11. function bootstrap_form_process($element, &$form_state, &$form) {
  12. if (!empty($element['#bootstrap_ignore_process'])) {
  13. return $element;
  14. }
  15. if (!empty($element['#attributes']['class']) && is_array($element['#attributes']['class'])) {
  16. $key = array_search('container-inline', $element['#attributes']['class']);
  17. if ($key !== FALSE) {
  18. $element['#attributes']['class'][$key] = 'form-inline';
  19. }
  20. if (in_array('form-wrapper', $element['#attributes']['class'])) {
  21. $element['#attributes']['class'][] = 'form-group';
  22. }
  23. }
  24. // Automatically inject the nearest button found after this element if
  25. // #input_group_button exists.
  26. if (!empty($element['#input_group_button'])) {
  27. // Obtain the parent array to limit search.
  28. $array_parents = array();
  29. if (!empty($element['#array_parents'])) {
  30. $array_parents += $element['#array_parents'];
  31. // Remove the current element from the array.
  32. array_pop($array_parents);
  33. }
  34. // If element is nested, return the referenced parent from the form.
  35. if (!empty($array_parents)) {
  36. $parent = &drupal_array_get_nested_value($form, $array_parents);
  37. }
  38. // Otherwise return the complete form.
  39. else {
  40. $parent = &$form;
  41. }
  42. // Ignore buttons before we find the element in the form.
  43. $found_current_element = FALSE;
  44. foreach (element_children($parent) as $child) {
  45. if ($parent[$child] === $element) {
  46. $found_current_element = TRUE;
  47. continue;
  48. }
  49. if ($found_current_element && _bootstrap_is_button($parent[$child])) {
  50. _bootstrap_iconize_button($parent[$child]);
  51. $element['#field_suffix'] = drupal_render($parent[$child]);
  52. break;
  53. }
  54. }
  55. }
  56. return $element;
  57. }
  58. /**
  59. * Implements hook_form_process_HOOK().
  60. */
  61. function bootstrap_form_process_actions($element, &$form_state, &$form) {
  62. $element['#attributes']['class'][] = 'form-actions';
  63. if (!empty($element['#bootstrap_ignore_process'])) {
  64. return $element;
  65. }
  66. foreach (element_children($element) as $child) {
  67. _bootstrap_iconize_button($element[$child]);
  68. }
  69. return $element;
  70. }
  71. /**
  72. * Implements hook_form_process_HOOK().
  73. */
  74. function bootstrap_form_process_text_format($element, &$form_state, &$form) {
  75. if (!empty($element['#bootstrap_ignore_process'])) {
  76. return $element;
  77. }
  78. // Provide smart description on the value text area.
  79. bootstrap_element_smart_description($element, $element['value']);
  80. // Allow the elements inside to be displayed inline.
  81. $element['format']['#attributes']['class'][] = 'form-inline';
  82. // Remove the cluttering guidelines; they can be viewed on a separate page.
  83. $element['format']['guidelines']['#access'] = FALSE;
  84. // Hide the select label.
  85. $element['format']['format']['#title_display'] = 'none';
  86. // Make the select element smaller using a Bootstrap class.
  87. $element['format']['format']['#attributes']['class'][] = 'input-sm';
  88. // Support the Bootstrap Select plugin if it is used.
  89. $element['format']['format']['#attributes']['data-style'] = 'btn-sm btn-default';
  90. return $element;
  91. }