function TestContextAwareBlock::build

Same name and namespace 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. 8.9.x core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php \Drupal\block_test\Plugin\Block\TestContextAwareBlock::build()
  3. 10 core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php \Drupal\block_test\Plugin\Block\TestContextAwareBlock::build()

Overrides BlockPluginInterface::build

File

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

Class

TestContextAwareBlock
Provides a context-aware block.

Namespace

Drupal\block_test\Plugin\Block

Code

public function build() {
    
    /** @var \Drupal\user\UserInterface $user */
    $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.