← All changes
|
app/Services/Integrations/FluentForms/BookingElement.php
+43
-4
2.2.5
→
2.5.0
View file →
| @@ -35,12 +35,12 @@ | ||
| 35 | 35 | 'advanced' |
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | add_filter('fluentform/response_render_fcal_booking', array($this, 'renderResponse'), 10, 3); |
| 39 | - add_filter('fluentform/select_group_component_ajax_options', array($this, 'getCalendarOptions')); | |
| 39 | + add_filter('fluentform/select_group_component_ajax_options', array($this, 'getCalendarOptions'), 10, 2); | |
| 40 | 40 | |
| 41 | 41 | add_action('fluentform/loading_editor_assets', function () { |
| 42 | - wp_enqueue_script('fluentcal_ff_editor_extended', FLUENT_BOOKING_URL . 'assets/admin/fluentform.js', [], '1.0.0', true); | |
| 42 | + wp_enqueue_script('fluentcal_ff_editor_extended', FLUENT_BOOKING_URL . 'assets/admin/fluentform.js', [], FLUENT_BOOKING_ASSETS_VERSION, true); | |
| 43 | 43 | }); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function getComponent() |
| @@ -247,11 +247,50 @@ | ||
| 247 | 247 | { |
| 248 | 248 | return __('Text Response', 'fluent-booking'); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - public function getCalendarOptions() | |
| 251 | + public function getCalendarOptions($options = [], $requestData = []) | |
| 252 | 252 | { |
| 253 | - return apply_filters('fluent_booking/ff_editor_calendar_options', CalendarService::getCalendarOptionsByHost()); | |
| 253 | + $eventId = (int) Arr::get($requestData, 'fcal_event_id'); | |
| 254 | + | |
| 255 | + if (!$eventId) { | |
| 256 | + return apply_filters('fluent_booking/ff_editor_calendar_options', CalendarService::getCalendarOptionsByHost()); | |
| 257 | + } | |
| 258 | + | |
| 259 | + return $this->getMappableFields($eventId); | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * Custom booking fields of an event that a Fluent Forms field can fill. | |
| 264 | + * File, checkbox and terms fields are left out: their stored value contract | |
| 265 | + * (a FluentBooking upload URL, 'Yes', 'Accepted') differs from what Fluent Forms submits. | |
| 266 | + * | |
| 267 | + * @param int $eventId | |
| 268 | + * @return array field name => label | |
| 269 | + */ | |
| 270 | + private function getMappableFields($eventId) | |
| 271 | + { | |
| 272 | + $event = CalendarSlot::find($eventId); | |
| 273 | + | |
| 274 | + if (!$event || !$event->calendar) { | |
| 275 | + return []; | |
| 276 | + } | |
| 277 | + | |
| 278 | + // Same scope as getCalendarOptionsByHost(): Fluent Forms only checks dashboard access. | |
| 279 | + if (!PermissionManager::hasAllCalendarAccess(true) && $event->calendar->user_id != get_current_user_id()) { | |
| 280 | + return []; | |
| 281 | + } | |
| 282 | + | |
| 283 | + $fields = []; | |
| 284 | + | |
| 285 | + foreach (BookingFieldService::getCustomFields($event, true) as $fieldKey => $field) { | |
| 286 | + if (in_array(Arr::get($field, 'type'), ['file', 'checkbox', 'terms-and-conditions'], true)) { | |
| 287 | + continue; | |
| 288 | + } | |
| 289 | + $fields[$fieldKey] = Arr::get($field, 'label', $fieldKey); | |
| 290 | + } | |
| 291 | + | |
| 292 | + return $fields; | |
| 254 | 293 | } |
| 255 | 294 | |
| 256 | 295 | /** |
| 257 | 296 | * Build unique ID concatenating form id and name attribute |