The Drupal\display_fields\AllTokens
class contains the following code.
private function coreReplace($string, $data, $settings = []) {
// @TODO: Remove this temp code.
// This is just here as a way to see all available tokens in debugger.
$tokens = $this->coreToken->getInfo();
$options = ['clear' => TRUE];
// Replace tokens with core Token service.
$replaced = $this->coreToken->replace($string, $data, $options);
// Ensure that there are no double-slash sequences due to empty token values.
$replaced = preg_replace('/(?<!:)\/+\//', '/', $replaced);
return $replaced;
}
/**
* Replace tokens with their values using the contributed token module.
*
* @param $string
* @param $data
* @param array $settings
*
* @return mixed|string
*/
private function contribReplace($string, $data, $settings = []) {
// @TODO: Add contrib Token integration when it is ready.
// For now, just redirect to the core replacement to avoid breaking sites
// where Token is installed.
return $this->coreReplace($string, $data, $settings);
}
That code is wrong: Whenever the Token module is installed, or not, the tokens in a string are replaced by calling Drupal\Core\Utility\Token::replace()
.
What the contributed module does is defining more token, altering tokens defined by core modules, and providing a theme hook to show a list of all the available tokens. It does not change how tokens are replaced, since that part of the Token module has been moved to Drupal core years ago.