You are here

public function DateApiToken::build in API Tokens 8.2

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

Build callback.

Parameters

string $format: (optional) The date format. Defaults to "U".

return array A renderable array.

See also

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

File

api_tokens_example/src/Plugin/ApiToken/DateApiToken.php, line 33

Class

DateApiToken
Provides a Date API token.

Namespace

Drupal\api_tokens_example\Plugin\ApiToken

Code

public function build($format = 'U') {
  $this
    ->mergeCacheMaxAge(0);
  $build = [
    '#type' => 'html_tag',
    '#tag' => 'span',
    '#value' => date($format),
    '#attributes' => [
      'class' => 'api-token-date',
    ],
    '#attached' => [
      'library' => [
        'api_tokens_example/date',
      ],
    ],
  ];
  return $build;
}