class BlockApiToken in API Tokens 8
Same name and namespace in other branches
- 8.2 api_tokens_example/src/Plugin/ApiToken/BlockApiToken.php \Drupal\api_tokens_example\Plugin\ApiToken\BlockApiToken
Provides a Block API token.
Token examples:
- [api:block["bartik_breadcrumbs"]/]
Plugin annotation
@ApiToken(
id = "block",
label = @Translation("Block"),
description = @Translation("Renders a block.")
)
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\BlockApiToken
- class \Drupal\api_tokens\ApiTokenBase implements ApiTokenPluginInterface uses RefinableCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BlockApiToken
File
- api_tokens_example/
src/ Plugin/ ApiToken/ BlockApiToken.php, line 20
Namespace
Drupal\api_tokens_example\Plugin\ApiTokenView source
class BlockApiToken extends ApiTokenBase {
/**
* {@inheritdoc}
*/
public function validate(array $params) {
// For [api:block["bartik_breadcrumbs"]/] token:
//$params = [
// 'id' => 'bartik_breadcrumbs',
//];
// Check that "id" is a string.
if (!is_string($params['id'])) {
return FALSE;
}
return TRUE;
}
/**
* Build callback.
*
* @param string $id
* The block ID.
*
* return array
* A renderable array.
*
* @see \Drupal\api_tokens\ApiTokenPluginInterface::build();
*/
public function build($id) {
$build = [];
$block = Block::load($id);
if ($block) {
$build = \Drupal::entityManager()
->getViewBuilder('block')
->view($block);
}
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 |
Performs one-time context-independent validation of the API token. Overrides ApiTokenPluginInterface:: |
|
ApiTokenBase:: |
public | function |
Constructs an ApiTokenBase object. Overrides PluginBase:: |
|
BlockApiToken:: |
public | function | Build callback. | |
BlockApiToken:: |
public | function |
Validates the API token parameters. Overrides ApiTokenBase:: |
|
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. | |
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. |