public function TokensReplacementEvent::setReplacementValue in Hook Event Dispatcher 8
Set's a replacement value for a token.
Parameters
string $type: The token type like 'node'.
string $token: The name of the token, like 'url'.
string|\Drupal\Component\Render\MarkupInterface $replacement: The replacement value.
Throws
\UnexpectedValueException
File
- src/
Event/ Token/ TokensReplacementEvent.php, line 218
Class
- TokensReplacementEvent
- Class TokensProvideEvent.
Namespace
Drupal\hook_event_dispatcher\Event\TokenCode
public function setReplacementValue($type, $token, $replacement) {
if (!is_string($type)) {
throw new UnexpectedValueException('Type should be a string');
}
if (!is_string($token)) {
throw new UnexpectedValueException('Token should be a string');
}
if (!$this
->forToken($type, $token)) {
throw new UnexpectedValueException('Requested replacement is not requested');
}
if (!is_string($replacement) && !$replacement instanceof MarkupInterface) {
throw new UnexpectedValueException('Replacement value should be a string or instanceof MarkupInterface');
}
$this->replacementValues["[{$type}:{$token}]"] = $replacement;
}