class DateApiToken in API Tokens 8
Same name and namespace in other branches
- 8.2 api_tokens_example/src/Plugin/ApiToken/DateApiToken.php \Drupal\api_tokens_example\Plugin\ApiToken\DateApiToken
Provides a Date API token.
Token examples:
- [api:date/]
- [api:date["D, d M y H:i:s"]/]
Plugin annotation
@ApiToken(
id = "date",
label = @Translation("Date"),
description = @Translation("Renders the current date.")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\api_tokens\ApiTokenBase implements ApiTokenPluginInterface uses RefinableCacheableDependencyTrait
- class \Drupal\api_tokens_example\Plugin\ApiToken\DateApiToken
- class \Drupal\api_tokens\ApiTokenBase implements ApiTokenPluginInterface uses RefinableCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DateApiToken
File
- api_tokens_example/
src/ Plugin/ ApiToken/ DateApiToken.php, line 20
Namespace
Drupal\api_tokens_example\Plugin\ApiTokenView source
class DateApiToken extends ApiTokenBase {
/**
* Build callback.
*
* @param string $format
* (optional) The date format. Defaults to "U".
*
* return array
* A renderable array.
*
* @see \Drupal\api_tokens\ApiTokenPluginInterface::build();
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ApiTokenBase:: |
protected static | property | The API token render context. | |
ApiTokenBase:: |
protected | property | The API token parameters hash. | |
ApiTokenBase:: |
protected | property | The API tokens logger. | |
ApiTokenBase:: |
protected | property | The module handler service. | |
ApiTokenBase:: |
protected | property | The API token parameters. | |
ApiTokenBase:: |
protected | property | The API token parameters string. | |
ApiTokenBase:: |
protected | property | The API token build method reflection object. | |
ApiTokenBase:: |
protected | property | The renderer. | |
ApiTokenBase:: |
protected | property | The API token string. | |
ApiTokenBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the administrative description of the API token. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns a build to replace the API token with in case of validation fail. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token parameters hash. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token ID. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the administrative label of the API token. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public static | function |
The #lazy_builder callback. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token parameters. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token parameter string. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns a #lazy_builder placeholder for the API tokens filter. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns processed API token build. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the name of the provider that owns this API token. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token build method reflection object. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Returns the API token string. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function | Validates the API token parameters. | 3 |
ApiTokenBase:: |
public | function |
Performs one-time context-independent validation of the API token. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Constructs an ApiTokenBase object. Overrides PluginBase:: |
|
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
DateApiToken:: |
public | function | Build callback. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |