| 1 |
<?php |
| 2 |
|
| 3 |
namespace Travelpayouts\components; |
| 4 |
|
| 5 |
use Travelpayouts; |
| 6 |
use Travelpayouts\components\HtmlHelper as Html; |
| 7 |
|
| 8 |
class ErrorHelper |
| 9 |
{ |
| 10 |
public static function render_errors($shortcode_name, $shortcode_errors, $show_key = false) |
| 11 |
{ |
| 12 |
$html = '[' . $shortcode_name . '] '; |
| 13 |
$html .= Travelpayouts::__('Shortcode validation failed:'); |
| 14 |
|
| 15 |
$html = Html::tag('span', [], $html); |
| 16 |
|
| 17 |
$errors = []; |
| 18 |
foreach ($shortcode_errors as $key => $error) { |
| 19 |
|
| 20 |
$error_msg = implode(' ', $error); |
| 21 |
if ($show_key) { |
| 22 |
$error_msg = Html::tag('span', [], "\"{$key}\": ") . $error_msg; |
| 23 |
} |
| 24 |
|
| 25 |
$errors[] = Html::tag('li', [], $error_msg); |
| 26 |
} |
| 27 |
|
| 28 |
$html .= Html::tag('ul', [], implode('', $errors)); |
| 29 |
|
| 30 |
return Html::tag( |
| 31 |
'div', |
| 32 |
[ |
| 33 |
'class' => TRAVELPAYOUTS_TEXT_DOMAIN . '-shortcode-validation-error' |
| 34 |
], |
| 35 |
$html |
| 36 |
); |
| 37 |
} |
| 38 |
} |
| 39 |
|