I'm trying to use the token service to replace a piece of text using a Taxonomy Term.
Example:
Hi [term:field_first_name], ...
The term is getting loaded correctly, but the text is not changing:
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
$token_service = \Drupal::token();
$text = $token_service->replace($text, [
'term' => $term,
]);
print_r($text);
The print returns:
Hi [term:field_first_name], ...
instead of:
Hi John, ...
I'm currently using drupal version 9.3.2.