function TypedDataResolver::getTokensForContexts

Same name in other branches
  1. 4.0.x src/TypedDataResolver.php \Drupal\ctools\TypedDataResolver::getTokensForContexts()

Extracts an array of tokens and labels.

Parameters

\Drupal\Core\Plugin\Context\ContextInterface[] $contexts: The array of contexts with which we are currently dealing.

Return value

array An array of token keys and corresponding labels.

1 call to TypedDataResolver::getTokensForContexts()
TypedDataResolver::getLabelByToken in src/TypedDataResolver.php
Provides an administrative label for a tokenized relationship.

File

src/TypedDataResolver.php, line 209

Class

TypedDataResolver
Typed Data Resolver Service.

Namespace

Drupal\ctools

Code

public function getTokensForContexts(array $contexts) {
    $tokens = [];
    foreach ($contexts as $context_id => $context) {
        $data_definition = $context->getContextDefinition()
            ->getDataDefinition();
        if ($data_definition instanceof ComplexDataDefinitionInterface) {
            foreach ($this->getTokensFromComplexData($data_definition) as $token => $label) {
                $tokens["{$context_id}:{$token}"] = $data_definition->getLabel() . ': ' . $label;
            }
        }
    }
    return $tokens;
}