public function Token::replace in Doubleclick for Publishers (DFP) 8
Replaces all tokens in a given string with appropriate values.
Parameters
string $text: An HTML string containing replaceable tokens.
\Drupal\dfp\View\TagView $tag: (optional) An TagView object that merges values of the Tag and global settings. Defaults to NULL.
array $options: (optional) A keyed array of settings and flags to control the token replacement process.
\Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata: (optional) An object to which static::generate() and the hooks and functions that it invokes will add their required bubbleable metadata. Defaults to NULL.
Return value
string The token result is the entered HTML text with tokens replaced. The caller is responsible for choosing the right escaping / sanitization. If the result is intended to be used as plain text, using PlainTextOutput::renderFromHtml() is recommended. If the result is just printed as part of a template relying on Twig autoescaping is possible, otherwise for example the result can be put into #markup, in which case it would be sanitized by Xss::filterAdmin().
Overrides TokenInterface::replace
See also
\Drupal\Core\Utility\Token::replace()
File
- src/
Token.php, line 54 - Contains \Drupal\dfp\Token.
Class
- Token
- A DFP token service to wrap core's service.
Namespace
Drupal\dfpCode
public function replace($text, TagView $tag = NULL, array $options = [], BubbleableMetadata $bubbleable_metadata = NULL) {
$data = [
'user' => $this->account,
];
if ($tag) {
$data['dfp_tag'] = $tag;
}
// Determine other data from the RouteMatch object.
$node = $this->routeMatch
->getParameter('node');
if ($node) {
$data['node'] = $node;
}
$term = $this->routeMatch
->getParameter('taxonomy_term');
if ($term) {
$data['term'] = $term;
}
return $this->coreToken
->replace($text, $data, $options, $bubbleable_metadata);
}