PluginProbe
The Innovative Form Builder – IvyForms / 1.4.1
The Innovative Form Builder – IvyForms v1.4.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Controllers / Form / ImportFormController.php

ImportFormController.php in The Innovative Form Builder – IvyForms 1.4.1, at backend/src/Controllers/Form/ImportFormController.php

51 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Controllers\Form;
4
5 use IvyForms\Common\Exceptions\ForbiddenException;
6 use IvyForms\Common\Exceptions\InvalidArgumentException;
7 use IvyForms\Common\Sanitizer\Sanitizer;
8 use IvyForms\Controllers\Controller;
9 use IvyForms\Services\Form\FormImportExportService;
10 use IvyForms\Services\Translations\BackendStrings;
11 use WP_REST_Request;
12 use WP_REST_Response;
13
14 class ImportFormController extends Controller
15 {
16 private FormImportExportService $importExportService;
17
18 public function __construct(FormImportExportService $importExportService)
19 {
20 $this->importExportService = $importExportService;
21 }
22
23 /**
24 * Handle the import request
25 *
26 * @param WP_REST_Request<array<string, mixed>> $data
27 * @return WP_REST_Response
28 * @throws ForbiddenException
29 * @throws InvalidArgumentException
30 */
31 public function handle(WP_REST_Request $data): WP_REST_Response
32 {
33 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
34
35 $importedForms = $this->importExportService->importFromRawPayload(
36 $data->get_param('importData')
37 );
38 if (empty($importedForms)) {
39 throw new InvalidArgumentException(
40 BackendStrings::getCommonStrings()['no_forms_imported']
41 );
42 }
43
44 return new WP_REST_Response([
45 'success' => true,
46 'data' => $importedForms,
47 'message' => BackendStrings::getCommonStrings()['forms_imported_successfully']
48 ], 200);
49 }
50 }
51