← All changes
|
backend/src/Controllers/Form/UpdateFormStatusController.php
+10
-10
0.2.1
→
1.5
View file →
| @@ -1,23 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See COPYING.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Controllers\Form; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use IvyForms\Common\Exceptions\ForbiddenException; |
| 16 | 11 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 17 | 12 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 18 | 13 | use IvyForms\Controllers\Controller; |
| 19 | 14 | use IvyForms\Services\Form\FormService; |
| 15 | +use IvyForms\Services\Translations\BackendStrings; | |
| 20 | 16 | use WP_REST_Request; |
| 21 | 17 | use WP_REST_Response; |
| 22 | 18 | |
| 23 | 19 | /** |
| @@ -22,9 +18,9 @@ | ||
| 22 | 18 | |
| 23 | 19 | /** |
| 24 | 20 | * Class UpdateFormController |
| 25 | 21 | * |
| 26 | - * @package IvyForms\Application\Controllers\Form | |
| 22 | + * @package IvyForms\Controllers\Form | |
| 27 | 23 | */ |
| 28 | 24 | class UpdateFormStatusController extends Controller |
| 29 | 25 | { |
| 30 | 26 | private FormService $formService; |
| @@ -49,15 +45,19 @@ | ||
| 49 | 45 | Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 50 | 46 | |
| 51 | 47 | // Check if the form data is provided |
| 52 | 48 | if (empty($data->get_params())) { |
| 53 | - throw new InvalidArgumentException('Invalid request data.'); | |
| 49 | + throw new InvalidArgumentException( | |
| 50 | + BackendStrings::getExceptionStrings()['invalid_request_data'] | |
| 51 | + ); | |
| 54 | 52 | } |
| 55 | 53 | |
| 56 | 54 | $formId = Sanitizer::sanitizeId($data->get_params()['id']); |
| 57 | 55 | |
| 58 | 56 | if ($formId <= 0) { |
| 59 | - throw new InvalidArgumentException('Invalid form ID.'); | |
| 57 | + throw new InvalidArgumentException( | |
| 58 | + BackendStrings::getExceptionStrings()['invalid_form_id'] | |
| 59 | + ); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $value = (bool)($data->get_params()['value']); |
| 63 | 63 | |
| @@ -64,9 +64,9 @@ | ||
| 64 | 64 | // Update the form status in the database |
| 65 | 65 | $this->formService->updateFormStatus($formId, $value); |
| 66 | 66 | |
| 67 | 67 | return new WP_REST_Response([ |
| 68 | - 'message' => 'Published status updated successfully', | |
| 68 | + 'message' => BackendStrings::getCommonStrings()['ok'], | |
| 69 | 69 | 'data' => [ |
| 70 | 70 | 'id' => $formId, |
| 71 | 71 | 'value' => $value, |
| 72 | 72 | ] |