PluginProbe
The Innovative Form Builder – IvyForms / 1.1.1
The Innovative Form Builder – IvyForms v1.1.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 / GetFormsController.php

GetFormsController.php in The Innovative Form Builder – IvyForms 1.1.1, at backend/src/Controllers/Form/GetFormsController.php

60 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Form;
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Sanitizer\Sanitizer;
13 use IvyForms\Controllers\Controller;
14 use IvyForms\Services\Form\FormService;
15 use IvyForms\Services\Translations\BackendStrings;
16 use WP_REST_Request;
17 use WP_REST_Response;
18
19 /**
20 * Class GetFormsController
21 *
22 * @package IvyForms\Controllers\Form
23 */
24 class GetFormsController extends Controller
25 {
26 private FormService $formService;
27 public function __construct(
28 FormService $formService
29 ) {
30 $this->formService = $formService;
31 }
32
33 /**
34 * @param WP_REST_Request $data
35 *
36 * @return WP_REST_Response
37 *
38 * @throws ForbiddenException
39 * @throws InvalidArgumentException
40 */
41 public function handle(WP_REST_Request $data): WP_REST_Response
42 {
43 // Verify the nonce
44 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
45
46 $formsArr = $this->formService->getAllForms();
47
48 $forms = [];
49
50 foreach ($formsArr as $form) {
51 $forms[] = $form->toArray();
52 }
53
54 return new WP_REST_Response([
55 'message' => BackendStrings::getCommonStrings()['ok'],
56 $forms
57 ], 200);
58 }
59 }
60