SystemMessagesBlock.php

Same filename and directory in other branches
  1. 9 core/modules/system/src/Plugin/Block/SystemMessagesBlock.php
  2. 8.9.x core/modules/system/src/Plugin/Block/SystemMessagesBlock.php
  3. 10 core/modules/system/src/Plugin/Block/SystemMessagesBlock.php

Namespace

Drupal\system\Plugin\Block

File

core/modules/system/src/Plugin/Block/SystemMessagesBlock.php

View source
<?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
 */
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;
    }

}

Classes

Title Deprecated Summary
SystemMessagesBlock Provides a block to display the messages.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.