PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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 / Routes / Template / Template.php

Template.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Routes/Template/Template.php

63 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Routes\Template;
4
5 use IvyForms\Vendor\DI\Container;
6 use IvyForms\Vendor\DI\DependencyException;
7 use IvyForms\Vendor\DI\NotFoundException;
8 use IvyForms\Controllers\Form\AddFormController;
9 use IvyForms\Controllers\Template\GetTemplatesController;
10 use IvyForms\Controllers\Template\GetTemplateController;
11 use IvyForms\Services\Permissions\RoutePermissionService;
12 use WP_REST_Server;
13
14 class Template
15 {
16 /**
17 * @throws DependencyException
18 * @throws NotFoundException
19 */
20 public static function registerRoutes(Container $container, string $routeNamespace): void
21 {
22 $routePermissionService = $container->get(RoutePermissionService::class);
23 // Get all templates
24 register_rest_route(
25 $routeNamespace,
26 '/templates',
27 [
28 'methods' => WP_REST_Server::READABLE,
29 'callback' => $container->get(GetTemplatesController::class),
30 'permission_callback' => static function () use ($routePermissionService) {
31 return $routePermissionService->canViewForms();
32 }
33 ]
34 );
35
36 // Get specific template by ID
37 register_rest_route(
38 $routeNamespace,
39 '/template/(?P<id>[a-zA-Z0-9_-]+)',
40 [
41 'methods' => WP_REST_Server::READABLE,
42 'callback' => $container->get(GetTemplateController::class),
43 'permission_callback' => static function () use ($routePermissionService) {
44 return $routePermissionService->canViewForms();
45 }
46 ]
47 );
48
49 // Create form from template
50 register_rest_route(
51 $routeNamespace,
52 '/template/create',
53 [
54 'methods' => WP_REST_Server::CREATABLE,
55 'callback' => $container->get(AddFormController::class),
56 'permission_callback' => static function () use ($routePermissionService) {
57 return $routePermissionService->canEditForms();
58 }
59 ]
60 );
61 }
62 }
63