1 | <?php |
||
2 | /** |
||
3 | * Elgg message element |
||
4 | * |
||
5 | * @uses $vars['type'] The type of message (error, success, warning, help, notice) |
||
6 | * @uses $vars['title'] Optional title text, will default to the type |
||
7 | * @uses $vars['icon_name'] Optional iconname to override default icon |
||
8 | * @uses $vars['body'] Content of the body |
||
9 | * @uses $vars['class'] Optional additional class for message |
||
10 | */ |
||
11 | |||
12 | $type = elgg_extract('type', $vars, false); |
||
13 | $title = elgg_extract('title', $vars); |
||
14 | $body = elgg_extract('body', $vars, ''); |
||
15 | |||
16 | if (empty($title) && empty($body)) { |
||
17 | return; |
||
18 | } |
||
19 | |||
20 | $attrs = [ |
||
21 | 'class' => elgg_extract_class($vars, 'elgg-message'), |
||
22 | ]; |
||
23 | |||
24 | if ($type) { |
||
25 | $attrs['class'][] = "elgg-message-$type"; |
||
26 | } |
||
27 | |||
28 | $default_icons = [ |
||
29 | 'error' => 'exclamation-circle', |
||
30 | 'help' => 'question-circle', |
||
31 | 'notice' => 'info-circle', |
||
32 | 'warning' => 'exclamation-triangle', |
||
33 | 'success' => 'check-circle', |
||
34 | ]; |
||
35 | |||
36 | $default_icon_name = elgg_extract($type, $default_icons); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
37 | $icon_name = elgg_extract('icon_name', $vars, $default_icon_name); |
||
38 | |||
39 | if (is_null($title) && !empty($type) && elgg_language_key_exists("messages:title:{$type}")) { |
||
40 | $title = elgg_echo("messages:title:{$type}"); |
||
41 | } |
||
42 | |||
43 | $header = ''; |
||
44 | if (!empty($title) && !empty($icon_name)) { |
||
45 | $header .= elgg_view_icon($icon_name, ['class' => 'elgg-message-icon']); |
||
46 | } |
||
47 | |||
48 | if (!empty($title)) { |
||
49 | $header .= elgg_format_element('span', ['class' => 'elgg-message-title'], $title); |
||
50 | } |
||
51 | |||
52 | if (!empty($header)) { |
||
53 | $header = elgg_format_element('div', ['class' => 'elgg-head'], $header); |
||
54 | } |
||
55 | |||
56 | if (!empty($body)) { |
||
57 | $body = elgg_format_element('div', ['class' => 'elgg-body'], $body); |
||
58 | } |
||
59 | |||
60 | $contents = elgg_format_element('div', ['class' => 'elgg-inner'], $header . $body); |
||
61 | |||
62 | echo elgg_format_element('div', $attrs, $contents); |
||
63 |