function NodeContextTestBlock::build

Same name and namespace in other branches
  1. 9 core/modules/node/tests/modules/node_block_test/src/Plugin/Block/NodeContextTestBlock.php \Drupal\node_block_test\Plugin\Block\NodeContextTestBlock::build()
  2. 10 core/modules/node/tests/modules/node_block_test/src/Plugin/Block/NodeContextTestBlock.php \Drupal\node_block_test\Plugin\Block\NodeContextTestBlock::build()

Overrides BlockPluginInterface::build

File

core/modules/node/tests/modules/node_block_test/src/Plugin/Block/NodeContextTestBlock.php, line 25

Class

NodeContextTestBlock
Provides a 'Node Context Test' block.

Namespace

Drupal\node_block_test\Plugin\Block

Code

public function build() {
    
    /** @var \Drupal\node\NodeInterface $node */
    $node = $this->getContextValue('node');
    return [
        '#type' => 'inline_template',
        '#template' => 'Displaying node #{{ id }}, revision #{{ revision_id }}: {{ title }}',
        '#context' => [
            'id' => $node->id(),
            'revision_id' => $node->getRevisionId(),
            'title' => $node->label(),
        ],
    ];
}

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