Mercurial > hg > isophonics-drupal-site
diff core/modules/system/src/Plugin/Block/SystemMessagesBlock.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,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 drupal_set_message() + * + * @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; + } + +}