ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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.

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

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);
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  }
static prepareFormOutput($a_str, bool $a_strip=false)
+ Here is the call graph for this function:

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