SystemMessagesBlock.php 992 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?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 drupal_set_message()
 *
 * @Block(
 *   id = "system_messages_block",
 *   admin_label = @Translation("Messages")
 * )
 */
class SystemMessagesBlock extends BlockBase implements MessagesBlockPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
25
    return [
26
      'label_display' => FALSE,
27
    ];
28 29 30 31 32 33 34 35 36 37 38 39
  }

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

  /**
   * {@inheritdoc}
   */
40
  public function getCacheMaxAge() {
41
    // The messages are session-specific and hence aren't cacheable, but the
42 43
    // block itself *is* cacheable because it uses a #lazy_builder callback and
    // hence the block has a globally cacheable render array.
44
    return Cache::PERMANENT;
45 46 47
  }

}