diff --git a/src/TokenResolver.php b/src/TokenResolver.php index c8ba1c8a3598c62065b50cd74d1b65e391cb894e..9be46cb6cc721ffc46e8085b9cb7093e39bef9cc 100644 --- a/src/TokenResolver.php +++ b/src/TokenResolver.php @@ -14,11 +14,11 @@ use Drupal\token\TokenEntityMapperInterface; class TokenResolver implements TokenResolverInterface { /** - * Token replacement instance. + * The token service. * - * @var \Drupal\Core\Utility\Token + * @var \Drupal\token\Token */ - protected $token; + protected $tokenService; /** * The token entity mapper. @@ -31,12 +31,12 @@ class TokenResolver implements TokenResolverInterface { * Constructs a TokenResolver object. * * @param \Drupal\Core\Utility\Token $token - * The token replacement instance. + * The token service. * @param \Drupal\token\TokenEntityMapperInterface $token_entity_mapper * The token entity mapper. */ - public function __construct(Token $token, TokenEntityMapperInterface $token_entity_mapper) { - $this->token = $token; + public function __construct(Token $token_service, TokenEntityMapperInterface $token_entity_mapper) { + $this->tokenService = $token_service; $this->tokenEntityMapper = $token_entity_mapper; } @@ -52,7 +52,7 @@ class TokenResolver implements TokenResolverInterface { $seititne = array_reverse($entity_objects); // Get it? foreach ($seititne as $entity_id => $entity) { - $replaced_string = $this->token->replace($replaced_string, [ + $replaced_string = $this->tokenService->replace($replaced_string, [ $entity_type => $entity, ]); } @@ -61,10 +61,17 @@ class TokenResolver implements TokenResolverInterface { // The entities might not have had values for all the tokens in the pattern. // Ensure that any remaining tokens are cleared from the string so they // don't get sent to the PDF. - $clean_replaced_string = $this->token->replace($replaced_string, [], ['clear' => TRUE]); + $clean_replaced_string = $this->tokenService->replace($replaced_string, [], ['clear' => TRUE]); return PlainTextOutput::renderFromHtml($clean_replaced_string); } + /** + * {@inheritdoc} + */ + public function getTokenService() { + return $this->tokenService; + } + /** * {@inheritdoc} */ diff --git a/src/TokenResolverInterface.php b/src/TokenResolverInterface.php index 45d81dc6461519f212e0d6aa5244f95cd82e8a9a..d581ba4417c9d98f928058865c2f6daab3da01d7 100644 --- a/src/TokenResolverInterface.php +++ b/src/TokenResolverInterface.php @@ -27,6 +27,14 @@ interface TokenResolverInterface { */ public function replace($original, array $entities); + /** + * Returns the token service. + * + * @return \Drupal\token\Token + * The token service. + */ + public function getTokenService(); + /** * Returns the token entity mapper. *