ILIAS  release_8 Revision v8.24
ilMailErrorFormatter Class Reference

Class ilMailErrorFormatter. More...

+ Collaboration diagram for ilMailErrorFormatter:

Public Member Functions

 __construct (ilLanguage $lng)
 
 format (array $errors)
 Formats an error string based on the passed list of errors. More...
 

Protected Attributes

ilLanguage $lng
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailErrorFormatter::__construct ( ilLanguage  $lng)

Definition at line 29 of file class.ilMailErrorFormatter.php.

References $lng, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ format()

ilMailErrorFormatter::format ( array  $errors)

Formats an error string based on the passed list of errors.

If the list contains > 1 elements, the 1st error will be used as a headline for the list of errors.

Parameters
ilMailError[]$errors

Definition at line 39 of file class.ilMailErrorFormatter.php.

39 : string
40 {
41 if (0 === count($errors)) {
42 return '';
43 }
44
45 $errorsToDisplay = [];
46 foreach ($errors as $error) {
47 $translation = $this->lng->txt($error->getLanguageVariable());
48 if ($translation === '-' . $error->getLanguageVariable() . '-') {
49 $translation = $error->getLanguageVariable();
50 }
51
52 if (
53 $translation === $error->getLanguageVariable() ||
54 0 === count($error->getPlaceHolderValues())
55 ) {
56 $errorsToDisplay[] = $translation;
57 } else {
58 $escapedPlaceholderValues = array_map(static function (string $address): string {
60 }, $error->getPlaceHolderValues());
61
62 array_unshift($escapedPlaceholderValues, $translation);
63 $errorsToDisplay[] = sprintf(...$escapedPlaceholderValues);
64 }
65 }
66
67 $tpl = new ilTemplate(
68 'tpl.mail_new_submission_errors.html',
69 true,
70 true,
71 'Services/Mail'
72 );
73 if (1 === count($errorsToDisplay)) {
74 $tpl->setCurrentBlock('single_error');
75 $tpl->setVariable('SINGLE_ERROR', current($errorsToDisplay));
76 } else {
77 $firstError = array_shift($errorsToDisplay);
78
79 foreach ($errorsToDisplay as $error) {
80 $tpl->setCurrentBlock('error_loop');
81 $tpl->setVariable('ERROR', $error);
82 $tpl->parseCurrentBlock();
83 }
84
85 $tpl->setCurrentBlock('multiple_errors');
86 $tpl->setVariable('FIRST_ERROR', $firstError);
87 }
88 $tpl->parseCurrentBlock();
89
90 return $tpl->get();
91 }
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
$errors
Definition: imgupload.php:65
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41

References $errors, $tpl, ILIAS\Repository\lng(), and ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

Field Documentation

◆ $lng

ilLanguage ilMailErrorFormatter::$lng
protected

Definition at line 27 of file class.ilMailErrorFormatter.php.

Referenced by __construct().


The documentation for this class was generated from the following file: