Guest User

Untitled

a guest
Aug 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. // Schedule fieldset.
  2. $form['schedule'] = [
  3. '#prefix' => '<div class="booking-fieldset-wrapper">',
  4. '#suffix' => '</div>',
  5. '#title' => t('Schedule'),
  6. '#type' => 'fieldset',
  7. '#weight' => $weight++,
  8. ];
  9. // Schedule pattern type.
  10. $form['schedule']['pattern_type'] = [
  11. '#prefix' => '<div class="row"><div class="col-md-5">',
  12. '#suffix' => '</div>',
  13. '#ajax' => [
  14. 'callback' => 'w_tpgal_services_bookings_schedule_callback',
  15. ],
  16. '#type' => 'radios',
  17. '#title' => t('Select the requested type of schedule'),
  18. '#options' => [
  19. BookingDTO::EVERY_X_DAYS => t('Every X days (Daily)'),
  20. BookingDTO::EVERY_X_WEEKS => t('Every X weeks (Weekly)'),
  21. BookingDTO::PICK_DATE_RANGE => t('Pick date range'),
  22. ],
  23. '#required' => TRUE,
  24. '#default_value' => !empty($form_state['values']) && !empty($form_state['values']['pattern_type']) ? $form_state['values']['pattern_type'] : BookingDTO::EVERY_X_DAYS,
  25. ];
  26. // Frequency.
  27. $form['schedule']['options']['frequency'] = [
  28. '#attributes' => [
  29. 'class' => ['js-select2'],
  30. ],
  31. '#prefix' => '<div class="row"><div class="col-md-6">',
  32. '#suffix' => '</div>',
  33. '#options' => ['' => t('-- Select --')] + $freq_options,
  34. '#default_value' => '',
  35. '#type' => 'select',
  36. '#title' => t('Frequency') . ' ' . theme_form_required_marker([]),
  37. // '#states' => [
  38. // 'disabled' => [
  39. // ':input[name="pattern_type"]' => ['value' => BookingDTO::PICK_DATE_RANGE],
  40. // ],
  41. // 'enabled' => [
  42. // ':input[name="pattern_type"]' => ['!value' => ''],
  43. // ],
  44. // ],
  45. ];
  46. // Pattern days.
  47. $form['schedule']['options']['pattern_days'] = [
  48. '#attributes' => [
  49. 'class' => ['js-select2'],
  50. ],
  51. '#prefix' => '<div class="col-md-6">',
  52. '#suffix' => '</div></div></div></div>',
  53. '#type' => 'select',
  54. '#title' => t('Day') . ' ' . theme_form_required_marker([]),
  55. '#options' => [
  56. '' => t('-- Select --'),
  57. BookingDTO::DAY_MONDAY => t('Monday'),
  58. BookingDTO::DAY_TUESDAY => t('Tuesday'),
  59. BookingDTO::DAY_WEDNESDAY => t('Wednesday'),
  60. BookingDTO::DAY_THURSDAY => t('Thursday'),
  61. BookingDTO::DAY_FRIDAY => t('Friday'),
  62. BookingDTO::DAY_SATURDAY => t('Saturday'),
  63. BookingDTO::DAY_SUNDAY => t('Sunday'),
  64. ],
  65. // '#states' => [
  66. // 'enabled' => [
  67. // ':input[name="pattern_type"]' => ['value' => BookingDTO::EVERY_X_WEEKS],
  68. // ],
  69. // 'disabled' => [
  70. // ':input[name="pattern_type"]' => ['!value' => ''],
  71. // ],
  72. // ],
  73. ];
  74.  
  75. function w_tpgal_services_bookings_schedule_callback($form, &$form_state) {
  76. $commands = [];
  77.  
  78. // Get selected option.
  79. if (!empty($form_state['values']['pattern_type'])) {
  80. $option = $form_state['values']['pattern_type'];
  81.  
  82. switch ($option) {
  83. case BookingDTO::EVERY_X_DAYS:
  84. $form['schedule']['options']['pattern_days']['#attributes']['disabled'] = TRUE;
  85. unset($form['schedule']['options']['frequency']['#attributes']['disabled']);
  86. break;
  87.  
  88. case BookingDTO::EVERY_X_WEEKS:
  89. unset($form['schedule']['options']['pattern_days']['#attributes']['disabled']);
  90. unset($form['schedule']['options']['frequency']['#attributes']['disabled']);
  91. break;
  92.  
  93. case BookingDTO::PICK_DATE_RANGE:
  94. $form['schedule']['options']['pattern_days']['#attributes']['disabled'] = TRUE;
  95. $form['schedule']['options']['frequency']['#attributes']['disabled'] = TRUE;
  96. break;
  97. }
  98. }
  99. $commands[] = ajax_command_replace('.schedule-fieldset-wrapper', render($form['schedule']['options']));
  100.  
  101. return ['#type' => 'ajax', '#commands' => $commands];
  102. }
Add Comment
Please, Sign In to add comment