3 namespace Drupal\block_test\Plugin\Block;
5 use Drupal\Core\Block\BlockBase;
8 * Provides a block to test caching.
12 * admin_label = @Translation("Test block caching")
15 class TestCacheBlock extends BlockBase {
20 public function build() {
21 $content = \Drupal::state()->get('block_test.content');
24 if (!empty($content)) {
25 $build['#markup'] = $content;
33 public function getCacheContexts() {
34 return \Drupal::state()->get('block_test.cache_contexts', []);
40 public function getCacheMaxAge() {
41 return \Drupal::state()->get('block_test.cache_max_age', parent::getCacheMaxAge());