You are here

public function NodeApiToken::build in API Tokens 8

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

Build callback.

Parameters

int $id: The node ID.

string $view_mode: (optional) The view mode to render a node in. Defaults to "full".

return array A renderable array.

See also

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

File

api_tokens_example/src/Plugin/ApiToken/NodeApiToken.php, line 60

Class

NodeApiToken
Provides a Node API token.

Namespace

Drupal\api_tokens_example\Plugin\ApiToken

Code

public function build($id, $view_mode = 'full') {
  $build = [];
  $node = Node::load($id);
  if ($node && $node
    ->access('view')) {
    $build = \Drupal::entityTypeManager()
      ->getViewBuilder('node')
      ->view($node, $view_mode);
  }
  return $build;
}