function NavigationTestBlock::build

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

File

core/modules/navigation/tests/navigation_test_block/src/Plugin/Block/NavigationTestBlock.php, line 26

Class

NavigationTestBlock
Defines a dummy navigation block for testing purposes.

Namespace

Drupal\navigation_test_block\Plugin\Block

Code

public function build() : array {
  $config = $this->configuration;
  $build = [];
  return $build + [
    '#title' => $config['label'],
    '#theme' => 'navigation_menu',
    '#menu_name' => 'test',
    '#items' => [
      [
        'title' => 'Test Navigation Block',
        'class' => 'test-block',
        'icon' => [
          'icon_id' => 'test-block',
        ],
        'url' => Url::fromRoute('<front>'),
      ],
    ],
  ];
}

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