NodeContextTestBlock.php

Same filename and directory in other branches
  1. 9 core/modules/node/tests/modules/node_block_test/src/Plugin/Block/NodeContextTestBlock.php
  2. 10 core/modules/node/tests/modules/node_block_test/src/Plugin/Block/NodeContextTestBlock.php

Namespace

Drupal\node_block_test\Plugin\Block

File

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

View source
<?php

namespace Drupal\node_block_test\Plugin\Block;

use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides a 'Node Context Test' block.
 */
class NodeContextTestBlock extends BlockBase {
    
    /**
     * {@inheritdoc}
     */
    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(),
            ],
        ];
    }

}

Classes

Title Deprecated Summary
NodeContextTestBlock Provides a 'Node Context Test' block.

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