ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilMailErrorFormatter Class Reference
+ Collaboration diagram for ilMailErrorFormatter:

Public Member Functions

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

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilMailErrorFormatter::__construct ( protected ilLanguage  $lng)

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

24 {
25 }

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
list<ilMailError>$errors

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

32 : 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);
72 }
73
74 $tpl->setCurrentBlock('multiple_errors');
75 $tpl->setVariable('FIRST_ERROR', $first_error);
76 }
78
79 return $tpl->get();
80 }
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
readonly ilGlobalTemplateInterface $tpl

References ILIAS\News\Common\Table\$tpl, ILIAS\UICore\GlobalTemplate\get(), ILIAS\Repository\lng(), ILIAS\UICore\GlobalTemplate\parseCurrentBlock(), ilLegacyFormElementsUtil\prepareFormOutput(), ILIAS\UICore\GlobalTemplate\setCurrentBlock(), and ILIAS\UICore\GlobalTemplate\setVariable().

+ Here is the call graph for this function:

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