ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailErrorFormatter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public function __construct(protected ilLanguage $lng)
24 {
25 }
26
32 public function format(array $errors): string
33 {
34 if ([] === $errors) {
35 return '';
36 }
37
38 $errors_to_display = [];
39 foreach ($errors as $error) {
40 $translation = $this->lng->txt($error->getLanguageVariable());
41 if ($translation === '-' . $error->getLanguageVariable() . '-') {
42 $translation = $error->getLanguageVariable();
43 }
44
45 if ($translation === $error->getLanguageVariable() || [] === $error->getPlaceHolderValues()) {
46 $errors_to_display[] = $translation;
47 } else {
48 $escaped_placeholder_values = array_map(static function (string $value): string {
50 }, $error->getPlaceHolderValues());
51
52 array_unshift($escaped_placeholder_values, $translation);
53 $errors_to_display[] = sprintf(...$escaped_placeholder_values);
54 }
55 }
56
57 $tpl = new ilTemplate(
58 'tpl.mail_new_submission_errors.html',
59 true,
60 true,
61 'components/ILIAS/Mail'
62 );
63 if (count($errors_to_display) === 1) {
64 $tpl->setCurrentBlock('single_error');
65 $tpl->setVariable('SINGLE_ERROR', current($errors_to_display));
66 } else {
67 $first_error = array_shift($errors_to_display);
68 foreach ($errors_to_display as $error) {
69 $tpl->setCurrentBlock('error_loop');
70 $tpl->setVariable('ERROR', $error);
71 $tpl->parseCurrentBlock();
72 }
73
74 $tpl->setCurrentBlock('multiple_errors');
75 $tpl->setVariable('FIRST_ERROR', $first_error);
76 }
77 $tpl->parseCurrentBlock();
78
79 return $tpl->get();
80 }
81}
language handling
static prepareFormOutput($a_str, bool $a_strip=false)
format(array $errors)
Formats an error string based on the passed list of errors.
__construct(protected ilLanguage $lng)
special template class to simplify handling of ITX/PEAR
global $lng
Definition: privfeed.php:31