public function TokensReplacementEvent::setReplacementValue in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/src/Event/Token/TokensReplacementEvent.php \Drupal\core_event_dispatcher\Event\Token\TokensReplacementEvent::setReplacementValue()
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
- modules/
core_event_dispatcher/ src/ Event/ Token/ TokensReplacementEvent.php, line 218
Class
- TokensReplacementEvent
- Class TokensProvideEvent.
Namespace
Drupal\core_event_dispatcher\Event\TokenCode
public function setReplacementValue(string $type, string $token, $replacement) : void {
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;
}