# ivyforms/0.5/backend/src/Services/Template/TemplateService.php

The Innovative Form Builder – IvyForms, version 0.5. 81 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Template/TemplateService.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.5/raw/backend/src/Services/Template/TemplateService.php
- Modified: 2025-10-23T15:35:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Template/TemplateService.php#L10-L20`.

```php
<?php

/**
 * @copyright © TMS-Plugins. All rights reserved.
 * @licence   See COPYING.md for license details.
 */

namespace IvyForms\Services\Template;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

use IvyForms\Common\Exceptions\InvalidArgumentException;
use IvyForms\Services\Translations\BackendStrings;

/**
 * Class TemplateService
 *
 * @package IvyForms\Services\Template
 */
class TemplateService
{
    /**
     * Get all predefined form templates
     *
     * @return array<string, array<string, mixed>>
     */
    public function getAllTemplates(): array
    {
        return TemplateMapper::getAllTemplates();
    }

    /**
     * Get predefined form template by ID
     *
     * @param string $templateId
     * @return array<string, mixed>|null
     */
    public function getTemplateById(string $templateId): ?array
    {
        return TemplateMapper::getTemplate($templateId);
    }

    /**
     * Get form data from template by ID
     *
     * @param string $templateId
     * @return array<string, mixed>
     * @throws InvalidArgumentException
     */
    public function getFormDataFromTemplate(string $templateId): array
    {
        $template = $this->getTemplateById($templateId);

        if (!$template) {
            throw new InvalidArgumentException(
                BackendStrings::getTemplateStrings()['template_not_found']
            );
        }

        return $template['form_data'];
    }

    /**
     * Get template categories
     *
     * @return array<string, array<string, string>>
     */
    public function getTemplateCategories(): array
    {
        return [
//            'basic' => [
//                'name' => '',
//                'description' => ''
//            ]
        ];
    }
}

```
