$draft Draft body. * @return array * * @throws DomainException When invalid. */ public function handle( array $draft ): array { $form_id = isset( $draft['form_id'] ) ? (int) $draft['form_id'] : 0; if ( $form_id <= 0 ) { throw new DomainException( 'booking_form.preview_invalid', 'Preview requires a form id.' ); } $existing = $this->forms->find_by_id( $form_id ); if ( null === $existing ) { throw new DomainException( 'booking_form.not_found', 'Booking form not found.' ); } $patch = []; foreach ( [ 'steps', 'service_ids', 'agent_ids', 'location_ids', 'category_ids', 'settings', 'theme' ] as $key ) { if ( array_key_exists( $key, $draft ) ) { $patch[ $key ] = $draft[ $key ]; } } $merged = $this->mutator->merge_patch( $existing, $patch, false ); return $this->sessions->create_preview_from_form( $merged, isset( $draft['timezone'] ) ? (string) $draft['timezone'] : null, isset( $draft['locale'] ) ? (string) $draft['locale'] : null, ); } }