1 token.inc token_get_invalid_tokens_by_context($value, array $valid_types = array())

Validate an tokens in raw text based on possible contexts.


string $value: A string with the raw text containing the raw tokens, or an array of tokens from token_scan().

array $valid_types: An array of token types that will be used when token replacement is performed.

Return value

array: An array with the invalid tokens in their original raw forms.


core/includes/token.inc, line 745
Backdrop placeholder/token replacement system.


function token_get_invalid_tokens_by_context($value, array $valid_types = array()) {
  if (in_array('all', $valid_types)) {
    $info = token_get_info();
    $valid_types = array_keys($info['types']);
  else {
    // Add the token types that are always valid in global context.
    $valid_types = array_merge($valid_types, token_get_global_token_types());

  $invalid_tokens = array();
  $value_tokens = is_string($value) ? token_scan($value) : $value;

  foreach ($value_tokens as $type => $tokens) {
    if (!in_array($type, $valid_types)) {
      // If the token type is not a valid context, its tokens are invalid.
      $invalid_tokens = array_merge($invalid_tokens, array_values($tokens));
    else {
      // Check each individual token for validity.
      $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($type, $tokens));

  return $invalid_tokens;