-
Notifications
You must be signed in to change notification settings - Fork 700
Expand file tree
/
Copy pathTemplateValidator.php
More file actions
51 lines (44 loc) · 1.14 KB
/
Copy pathTemplateValidator.php
File metadata and controls
51 lines (44 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\validators;
use Craft;
use craft\web\View;
use yii\validators\Validator;
/**
* Class TemplateValidator.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.1.0
*/
class TemplateValidator extends Validator
{
/**
* @var string The template mode to use when looking for the template
* @phpstan-var View::TEMPLATE_MODE_SITE|View::TEMPLATE_MODE_CP
*/
public string $templateMode = View::TEMPLATE_MODE_SITE;
/**
* @inheritdoc
*/
public function init(): void
{
parent::init();
if (!isset($this->message)) {
$this->message = str_replace('{template}', '{value}', Craft::t('app', 'Unable to find the template “{template}”.'));
}
}
/**
* @inheritdoc
*/
public function validateValue($value): ?array
{
if (Craft::$app->getView()->resolveTemplate($value, $this->templateMode) === false) {
return [$this->message, []];
}
return null;
}
}