Skip to content
Snippets Groups Projects
Commit 182acd2a authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3057401 by Pancho, wizonesolutions: Add a getter for TokenResolver->tokenService

parent 2327789e
No related branches found
No related tags found
No related merge requests found
...@@ -14,11 +14,11 @@ use Drupal\token\TokenEntityMapperInterface; ...@@ -14,11 +14,11 @@ use Drupal\token\TokenEntityMapperInterface;
class TokenResolver implements TokenResolverInterface { 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. * The token entity mapper.
...@@ -31,12 +31,12 @@ class TokenResolver implements TokenResolverInterface { ...@@ -31,12 +31,12 @@ class TokenResolver implements TokenResolverInterface {
* Constructs a TokenResolver object. * Constructs a TokenResolver object.
* *
* @param \Drupal\Core\Utility\Token $token * @param \Drupal\Core\Utility\Token $token
* The token replacement instance. * The token service.
* @param \Drupal\token\TokenEntityMapperInterface $token_entity_mapper * @param \Drupal\token\TokenEntityMapperInterface $token_entity_mapper
* The token entity mapper. * The token entity mapper.
*/ */
public function __construct(Token $token, TokenEntityMapperInterface $token_entity_mapper) { public function __construct(Token $token_service, TokenEntityMapperInterface $token_entity_mapper) {
$this->token = $token; $this->tokenService = $token_service;
$this->tokenEntityMapper = $token_entity_mapper; $this->tokenEntityMapper = $token_entity_mapper;
} }
...@@ -52,7 +52,7 @@ class TokenResolver implements TokenResolverInterface { ...@@ -52,7 +52,7 @@ class TokenResolver implements TokenResolverInterface {
$seititne = array_reverse($entity_objects); // Get it? $seititne = array_reverse($entity_objects); // Get it?
foreach ($seititne as $entity_id => $entity) { foreach ($seititne as $entity_id => $entity) {
$replaced_string = $this->token->replace($replaced_string, [ $replaced_string = $this->tokenService->replace($replaced_string, [
$entity_type => $entity, $entity_type => $entity,
]); ]);
} }
...@@ -61,10 +61,17 @@ class TokenResolver implements TokenResolverInterface { ...@@ -61,10 +61,17 @@ class TokenResolver implements TokenResolverInterface {
// The entities might not have had values for all the tokens in the pattern. // 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 // Ensure that any remaining tokens are cleared from the string so they
// don't get sent to the PDF. // 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); return PlainTextOutput::renderFromHtml($clean_replaced_string);
} }
/**
* {@inheritdoc}
*/
public function getTokenService() {
return $this->tokenService;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -27,6 +27,14 @@ interface TokenResolverInterface { ...@@ -27,6 +27,14 @@ interface TokenResolverInterface {
*/ */
public function replace($original, array $entities); 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. * Returns the token entity mapper.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment