PluginProbe
The Innovative Form Builder – IvyForms / 0.6
The Innovative Form Builder – IvyForms v0.6
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 / Services / Template / TemplateService.php

TemplateService.php in The Innovative Form Builder – IvyForms 0.6, at backend/src/Services/Template/TemplateService.php

81 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Services\Template;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\InvalidArgumentException;
16 use IvyForms\Services\Translations\BackendStrings;
17
18 /**
19 * Class TemplateService
20 *
21 * @package IvyForms\Services\Template
22 */
23 class TemplateService
24 {
25 /**
26 * Get all predefined form templates
27 *
28 * @return array<string, array<string, mixed>>
29 */
30 public function getAllTemplates(): array
31 {
32 return TemplateMapper::getAllTemplates();
33 }
34
35 /**
36 * Get predefined form template by ID
37 *
38 * @param string $templateId
39 * @return array<string, mixed>|null
40 */
41 public function getTemplateById(string $templateId): ?array
42 {
43 return TemplateMapper::getTemplate($templateId);
44 }
45
46 /**
47 * Get form data from template by ID
48 *
49 * @param string $templateId
50 * @return array<string, mixed>
51 * @throws InvalidArgumentException
52 */
53 public function getFormDataFromTemplate(string $templateId): array
54 {
55 $template = $this->getTemplateById($templateId);
56
57 if (!$template) {
58 throw new InvalidArgumentException(
59 BackendStrings::getTemplateStrings()['template_not_found']
60 );
61 }
62
63 return $template['form_data'];
64 }
65
66 /**
67 * Get template categories
68 *
69 * @return array<string, array<string, string>>
70 */
71 public function getTemplateCategories(): array
72 {
73 return [
74 // 'basic' => [
75 // 'name' => '',
76 // 'description' => ''
77 // ]
78 ];
79 }
80 }
81