public function WebformElementBase::replaceTokens in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::replaceTokens()
Replace tokens for all element properties.
Parameters
array $element: An element.
\Drupal\Core\Entity\EntityInterface|null $entity: A webform or webform submission entity.
Overrides WebformElementInterface::replaceTokens
1 call to WebformElementBase::replaceTokens()
- WebformElementBase::prepare in src/
Plugin/ WebformElementBase.php - Prepare an element to be rendered within a webform.
File
- src/
Plugin/ WebformElementBase.php, line 1031
Class
- WebformElementBase
- Provides a base class for a webform element.
Namespace
Drupal\webform\PluginCode
public function replaceTokens(array &$element, EntityInterface $entity = NULL) {
$bubbleable_metadata = new WebformBubbleableMetadata();
foreach ($element as $key => $value) {
// Only replace tokens in properties.
if (Element::child($key)) {
continue;
}
// Ignore tokens in #template and #format_* properties.
if (in_array($key, [
'#template',
'#format_html',
'#format_text',
'format_items_html',
'format_items_text',
])) {
continue;
}
$element[$key] = $this->tokenManager
->replace($value, $entity, [], [], $bubbleable_metadata);
}
// Append metadata to the element's #cache property.
$bubbleable_metadata
->appendTo($element);
}