DonateController.php
2 years ago
DonationConfirmationReceiptViewController.php
1 year ago
DonationFormViewController.php
3 months ago
DonationFormsRequestController.php
5 months ago
DonationFormViewController.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms\Controllers; |
| 4 | |
| 5 | use Give\DonationForms\DataTransferObjects\DonationFormPreviewRouteData; |
| 6 | use Give\DonationForms\DataTransferObjects\DonationFormViewRouteData; |
| 7 | use Give\DonationForms\Models\DonationForm; |
| 8 | use Give\DonationForms\ViewModels\DonationFormViewModel; |
| 9 | |
| 10 | class DonationFormViewController |
| 11 | { |
| 12 | /** |
| 13 | * This renders the donation form view. |
| 14 | * |
| 15 | * @since 4.14.3 Prevent triggering a fatal error due to form not found. |
| 16 | * @since 3.0.0 |
| 17 | */ |
| 18 | public function show(DonationFormViewRouteData $data): string |
| 19 | { |
| 20 | /** @var DonationForm $donationForm */ |
| 21 | $donationForm = DonationForm::find($data->formId); |
| 22 | |
| 23 | if (!$donationForm) { |
| 24 | wp_die( |
| 25 | esc_html__('Donation form not found.', 'give'), |
| 26 | esc_html__('Not Found', 'give'), |
| 27 | ['response' => 404] |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | $viewModel = new DonationFormViewModel( |
| 32 | $donationForm->id, |
| 33 | $donationForm->blocks, |
| 34 | $donationForm->settings |
| 35 | ); |
| 36 | |
| 37 | ob_clean(); |
| 38 | return $viewModel->render(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * This renders the donation form preview |
| 43 | * |
| 44 | * @since 4.14.3 Prevent triggering a fatal error due to form not found. |
| 45 | * @since 3.0.0 |
| 46 | */ |
| 47 | public function preview(DonationFormPreviewRouteData $data): string |
| 48 | { |
| 49 | /** @var DonationForm $donationForm */ |
| 50 | $donationForm = DonationForm::find($data->formId); |
| 51 | |
| 52 | if (!$donationForm) { |
| 53 | wp_die( |
| 54 | esc_html__('Donation form not found.', 'give'), |
| 55 | esc_html__('Not Found', 'give'), |
| 56 | ['response' => 404] |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | $viewModel = new DonationFormViewModel( |
| 61 | $donationForm->id, |
| 62 | $data->formBlocks ?: $donationForm->blocks, |
| 63 | $data->formSettings ?: $donationForm->settings, |
| 64 | true |
| 65 | ); |
| 66 | |
| 67 | ob_clean(); |
| 68 | return $viewModel->render(); |
| 69 | } |
| 70 | } |
| 71 |