-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatusMessages.php
More file actions
53 lines (44 loc) · 1.24 KB
/
Copy pathStatusMessages.php
File metadata and controls
53 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Drupal\workbench_tabs\Element;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\RenderElement;
/**
* Provides a render element for the status messages.
*
* Unlike Drupal\Core\Render\Element\StatusMessages, this element clears the
* messages when it renders them, so that they are only displayed once on the
* page.
*
* @RenderElement("workbench_tabs_status_messages")
*/
class StatusMessages extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#pre_render' => [[$class, 'renderMessages']],
'#message_type' => NULL,
'#clear_queue' => TRUE,
];
}
/**
* Clear the message queue when rendering the messages.
*/
public static function renderMessages($element) {
$messages = drupal_get_messages($element['#message_type'], $element['#clear_queue']);
if (!empty($messages)) {
$element = [
'#theme' => 'workbench_tabs_status_messages',
'#message_list' => $messages,
'#status_headings' => [
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
],
] + $element;
}
return $element;
}
}