You are here

public function BlockApiToken::build in API Tokens 8

Same name and namespace in other branches
  1. 8.2 api_tokens_example/src/Plugin/ApiToken/BlockApiToken.php \Drupal\api_tokens_example\Plugin\ApiToken\BlockApiToken::build()

Build callback.

Parameters

string $id: The block ID.

return array A renderable array.

See also

\Drupal\api_tokens\ApiTokenPluginInterface::build();

File

api_tokens_example/src/Plugin/ApiToken/BlockApiToken.php, line 50

Class

BlockApiToken
Provides a Block API token.

Namespace

Drupal\api_tokens_example\Plugin\ApiToken

Code

public function build($id) {
  $build = [];
  $block = Block::load($id);
  if ($block) {
    $build = \Drupal::entityManager()
      ->getViewBuilder('block')
      ->view($block);
  }
  return $build;
}