ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailErrorFormatter Class Reference

Class ilMailErrorFormatter. More...

+ 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

Constructor & Destructor Documentation

◆ __construct()

ilMailErrorFormatter::__construct ( protected ilLanguage  $lng)

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

28  {
29  }

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 36 of file class.ilMailErrorFormatter.php.

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

36  : string
37  {
38  if ([] === $errors) {
39  return '';
40  }
41 
42  $errorsToDisplay = [];
43  foreach ($errors as $error) {
44  $translation = $this->lng->txt($error->getLanguageVariable());
45  if ($translation === '-' . $error->getLanguageVariable() . '-') {
46  $translation = $error->getLanguageVariable();
47  }
48 
49  if (
50  $translation === $error->getLanguageVariable() ||
51  [] === $error->getPlaceHolderValues()
52  ) {
53  $errorsToDisplay[] = $translation;
54  } else {
55  $escapedPlaceholderValues = array_map(static function (string $address): string {
57  }, $error->getPlaceHolderValues());
58 
59  array_unshift($escapedPlaceholderValues, $translation);
60  $errorsToDisplay[] = sprintf(...$escapedPlaceholderValues);
61  }
62  }
63 
64  $tpl = new ilTemplate(
65  'tpl.mail_new_submission_errors.html',
66  true,
67  true,
68  'components/ILIAS/Mail'
69  );
70  if (1 === count($errorsToDisplay)) {
71  $tpl->setCurrentBlock('single_error');
72  $tpl->setVariable('SINGLE_ERROR', current($errorsToDisplay));
73  } else {
74  $firstError = array_shift($errorsToDisplay);
75 
76  foreach ($errorsToDisplay as $error) {
77  $tpl->setCurrentBlock('error_loop');
78  $tpl->setVariable('ERROR', $error);
79  $tpl->parseCurrentBlock();
80  }
81 
82  $tpl->setCurrentBlock('multiple_errors');
83  $tpl->setVariable('FIRST_ERROR', $firstError);
84  }
85  $tpl->parseCurrentBlock();
86 
87  return $tpl->get();
88  }
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: