You are here

protected function ApiTokenController::buildSynopsis in API Tokens 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ApiTokenController.php \Drupal\api_tokens\Controller\ApiTokenController::buildSynopsis()

Renders the API token synopsis.

Parameters

string $id: The API token plugin ID.

Return value

array A renderable array.

1 call to ApiTokenController::buildSynopsis()
ApiTokenController::adminOverview in src/Controller/ApiTokenController.php
Displays the API tokens overview page.

File

src/Controller/ApiTokenController.php, line 87

Class

ApiTokenController
Controller routines for API tokens routes.

Namespace

Drupal\api_tokens\Controller

Code

protected function buildSynopsis($id) {
  $plugin = $this->apiTokenManager
    ->createInstance($id);
  $parts = [];
  foreach ($plugin
    ->reflector()
    ->getParameters() as $param) {
    $name = $param
      ->getName();
    if (!$param
      ->isOptional()) {
      $name = "<strong>{$name}</strong>";
    }
    $parts[] = "<em>{$name}</em>";
  }
  $params = $parts ? '[' . implode(', ', $parts) . ']' : '';
  $build = [
    '#type' => 'html_tag',
    '#tag' => 'code',
    '#value' => "[api:{$id}{$params}/]",
  ];
  return $build;
}