protected function TokenReplacer::getReplacementsForTokenType in Advanced Entity Tokens 2.x
Fetches token replacements for specific token types.
Each token type should map to an entity type ID, which is the second part of the token. e.g. "node" in [aet:node:1] and "file" in [aet:file:label].
Parameters
string $token_type: The type of token, e.g. "node" or "file".
array $tokens: The tokens to replace.
Return value
array The replacements.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to TokenReplacer::getReplacementsForTokenType()
- TokenReplacer::getReplacements in src/
TokenReplacer.php - Fetches replacements for the provided tokens.
File
- src/
TokenReplacer.php, line 239
Class
- TokenReplacer
- Class TokenReplacer.
Namespace
Drupal\aetCode
protected function getReplacementsForTokenType(string $token_type, array $tokens) {
list($entity_type_id, $entity_type_info) = $this
->getEntityInfoMatchingTokenType($token_type);
if (empty($entity_type_info)) {
return [];
}
$replacements = [];
foreach ($tokens as $key => $original) {
if (!$this
->entityIdIsValid($entity_id = $this
->getEntityIdFromTokenKey($key)) || $this
->recursiveTokenUseDetected($entity_type_id, $entity_type_info
->getKey('id'), $entity_id)) {
continue;
}
if ($entity = $this
->getEntityFromId($entity_type_id, $entity_id)) {
$replacements += $this
->getReplacementsForEntity($entity_type_id, $entity, $token_type, $tokens);
}
}
return $this
->getReplacementsWithUnreplacedTokensClearedIfSet($tokens, $replacements);
}