summaryrefslogtreecommitdiffstats
path: root/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php
blob: 99901957e761e66271548a06a0ec7e18e972429e (plain)
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
<?php

namespace Drupal\system\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\MessagesBlockPluginInterface;
use Drupal\Core\Cache\Cache;

/**
 * Provides a block to display the messages.
 *
 * @see @see \Drupal\Core\Messenger\MessengerInterface
 *
 * @Block(
 *   id = "system_messages_block",
 *   admin_label = @Translation("Messages")
 * )
 */
class SystemMessagesBlock extends BlockBase implements MessagesBlockPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'label_display' => FALSE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    return ['#type' => 'status_messages'];
  }

  /**
   * {@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;
  }

}