function TestContextAwareBlock::build

Same name in other branches
  1. 9 core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php \Drupal\block_test\Plugin\Block\TestContextAwareBlock::build()
  2. 10 core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php \Drupal\block_test\Plugin\Block\TestContextAwareBlock::build()
  3. 11.x core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php \Drupal\block_test\Plugin\Block\TestContextAwareBlock::build()

File

core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php, line 27

Class

TestContextAwareBlock
Provides a context-aware block.

Namespace

Drupal\block_test\Plugin\Block

Code

public function build() {
    
    /** @var $user \Drupal\user\UserInterface */
    $user = $this->getContextValue('user');
    return [
        '#prefix' => '<div id="' . $this->getPluginId() . '--username">',
        '#suffix' => '</div>',
        '#markup' => $user ? $user->getAccountName() : 'No context mapping selected.',
    ];
}

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