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, TRUE) 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]) && (!isset($parent[$child]['#access']) || !!$parent[$child]['#access'])) {
  50. $element['#field_suffix'] = drupal_render($parent[$child]);
  51. break;
  52. }
  53. }
  54. }
  55. return $element;
  56. }
  57. /**
  58. * Implements hook_form_process_HOOK().
  59. */
  60. function bootstrap_form_process_actions($element, &$form_state, &$form) {
  61. $element['#attributes']['class'][] = 'form-actions';
  62. if (!empty($element['#bootstrap_ignore_process'])) {
  63. return $element;
  64. }
  65. foreach (element_children($element) as $child) {
  66. _bootstrap_iconize_button($element[$child]);
  67. }
  68. return $element;
  69. }
  70. /**
  71. * Implements hook_form_process_HOOK().
  72. */
  73. function bootstrap_form_process_text_format($element, &$form_state, &$form) {
  74. if (!empty($element['#bootstrap_ignore_process'])) {
  75. return $element;
  76. }
  77. // Provide smart description on the value text area.
  78. bootstrap_element_smart_description($element, $element['value']);
  79. // Allow the elements inside to be displayed inline.
  80. $element['format']['#attributes']['class'][] = 'form-inline';
  81. // Remove the cluttering guidelines; they can be viewed on a separate page.
  82. $element['format']['guidelines']['#access'] = FALSE;
  83. // Hide the select label.
  84. $element['format']['format']['#title_display'] = 'none';
  85. // Make the select element smaller using a Bootstrap class.
  86. $element['format']['format']['#attributes']['class'][] = 'input-sm';
  87. // Support the Bootstrap Select plugin if it is used.
  88. $element['format']['format']['#attributes']['data-style'] = 'btn-sm btn-default';
  89. return $element;
  90. }