You are here

public function BlockApiToken::validate in API Tokens 8.2

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

Validates the API token parameters.

This validation must be context-independent. For example, if some parameter is expected to be an entity ID, check only whether it is a valid entity ID, but don't check the entity existence/access (these must be checked in the build method).

Parameters

array $params: An array of named API token parameters. If an API token has more parameters then it is defined in build method, extra parameters will be named by parameter index. For example, if we have the API token [api:example[123, ["option1", "option2"], "extra1", "extra2"]/], and plugin's build method argument definition is: ...($id, $options), the $params will be:

[
  'id' => 123,
  'options' => [
    'option1',
    'option2',
  ],
  '2' => 'extra1',
  '3' => 'extra2',
];

Return value

bool

Overrides ApiTokenBase::validate

See also

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

File

api_tokens_example/src/Plugin/ApiToken/BlockApiToken.php, line 25

Class

BlockApiToken
Provides a Block API token.

Namespace

Drupal\api_tokens_example\Plugin\ApiToken

Code

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;
}