Commit | Line | Data |
---|---|---|
5ad80eb9 | 1 | <?php |
a9229942 | 2 | |
5ad80eb9 | 3 | namespace wcf\system\form\builder\field\validation; |
a9229942 | 4 | |
5ad80eb9 MS |
5 | use wcf\system\WCF; |
6 | ||
7 | /** | |
8 | * Represents an error that occured during the validation of a form field. | |
a9229942 TD |
9 | * |
10 | * @author Matthias Schmidt | |
11 | * @copyright 2001-2019 WoltLab GmbH | |
12 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
13 | * @package WoltLabSuite\Core\System\Form\Builder\Field\Validation | |
14 | * @since 5.2 | |
5ad80eb9 | 15 | */ |
a9229942 TD |
16 | class FormFieldValidationError implements IFormFieldValidationError |
17 | { | |
18 | /** | |
19 | * additional error information, also used to resolve error message from language item | |
20 | * @var array | |
21 | */ | |
22 | protected $information; | |
23 | ||
24 | /** | |
25 | * language item containing the error message | |
26 | * @var string | |
27 | */ | |
28 | protected $languageItem; | |
29 | ||
30 | /** | |
31 | * error type | |
32 | * @var string | |
33 | */ | |
34 | protected $type; | |
35 | ||
36 | /** | |
37 | * @inheritDoc | |
38 | */ | |
39 | public function __construct($type, $languageItem = null, array $information = []) | |
40 | { | |
41 | if ($languageItem === null) { | |
42 | $languageItem = 'wcf.global.form.error.' . $type; | |
43 | } elseif (!\is_string($languageItem)) { | |
44 | throw new \InvalidArgumentException( | |
45 | "Given language item is no string, '" . \gettype($languageItem) . "' given.'" | |
46 | ); | |
47 | } | |
48 | ||
49 | $this->type = $type; | |
50 | $this->languageItem = $languageItem; | |
51 | $this->information = $information; | |
52 | } | |
53 | ||
54 | /** | |
55 | * @inheritDoc | |
56 | */ | |
57 | public function getHtml() | |
58 | { | |
59 | return WCF::getTPL()->fetch('__formFieldError', 'wcf', [ | |
60 | 'error' => $this, | |
61 | ]); | |
62 | } | |
63 | ||
64 | /** | |
65 | * @inheritDoc | |
66 | */ | |
67 | public function getInformation() | |
68 | { | |
69 | return $this->information; | |
70 | } | |
71 | ||
72 | /** | |
73 | * @inheritDoc | |
74 | */ | |
75 | public function getMessage() | |
76 | { | |
77 | return WCF::getLanguage()->getDynamicVariable($this->languageItem, $this->information); | |
78 | } | |
79 | ||
80 | /** | |
81 | * @inheritDoc | |
82 | */ | |
83 | public function getType() | |
84 | { | |
85 | return $this->type; | |
86 | } | |
5ad80eb9 | 87 | } |