blob: d6f1a9f22758baaf01177e671cd1788d6ea72810 (
plain) (
blame)
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
|
<?php
namespace Drupal\system\Plugin\Block;
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\MessagesBlockPluginInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Provides a block to display the messages.
*
* @see @see \Drupal\Core\Messenger\MessengerInterface
*/
#[Block(
id: "system_messages_block",
admin_label: new TranslatableMarkup("Messages")
)]
class SystemMessagesBlock extends BlockBase implements MessagesBlockPluginInterface {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'label_display' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function build() {
return [
'#type' => 'status_messages',
'#include_fallback' => TRUE,
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// The messages are session-specific and hence aren't cacheable, but the
// block itself *is* cacheable because it uses a #lazy_builder callback and
// hence the block has a globally cacheable render array.
return Cache::PERMANENT;
}
}
|