ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailErrorFormatter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  protected ilLanguage $lng;
28 
29  public function __construct(ilLanguage $lng)
30  {
31  $this->lng = $lng;
32  }
33 
39  public function format(array $errors): 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  }
92 }
$errors
Definition: imgupload.php:65
Class ilMailErrorFormatter.
static prepareFormOutput($a_str, bool $a_strip=false)
format(array $errors)
Formats an error string based on the passed list of errors.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41