RouteAbstract.php
1 week ago
RouteIntegration.php
1 week ago
RouteInterface.php
1 week ago
UpdateFormFieldsRoute.php
1 week ago
UpdateFormSettingsRoute.php
1 week ago
UpdateFormFieldsRoute.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Settings\Route; |
| 4 | |
| 5 | use WPDesk\FCF\Free\Collections\RouteParamBag; |
| 6 | use WPDesk\FCF\Free\Settings\Form\EditFieldsForm; |
| 7 | |
| 8 | /** |
| 9 | * {@inheritdoc} |
| 10 | */ |
| 11 | class UpdateFormFieldsRoute extends RouteAbstract { |
| 12 | |
| 13 | const REST_API_ROUTE = '(?P<form_section>[a-z_]+)/fields'; |
| 14 | |
| 15 | /** |
| 16 | * {@inheritdoc} |
| 17 | */ |
| 18 | public function get_endpoint_route(): string { |
| 19 | return self::REST_API_ROUTE; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * {@inheritdoc} |
| 24 | */ |
| 25 | public function get_route_params(): array { |
| 26 | return [ |
| 27 | 'form_section' => [ |
| 28 | 'description' => 'Section name', |
| 29 | 'required' => true, |
| 30 | ], |
| 31 | 'form_fields' => [ |
| 32 | 'description' => 'Form fields', |
| 33 | 'required' => true, |
| 34 | ], |
| 35 | ]; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * {@inheritdoc} |
| 40 | * |
| 41 | * @throws \Exception |
| 42 | */ |
| 43 | public function get_endpoint_response( RouteParamBag $params ) { |
| 44 | try { |
| 45 | $status = ( new EditFieldsForm() )->save_form_data( $params->toArray() ); |
| 46 | if ( $status !== true ) { |
| 47 | throw new \Exception(); |
| 48 | } |
| 49 | |
| 50 | return null; |
| 51 | } catch ( \Exception $e ) { |
| 52 | throw $e; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 |