public function TokenFilter::process in Token Filter 8
Performs the filter processing.
Parameters
string $text: The text string to be filtered.
string $langcode: The language code of the text to be filtered.
Return value
\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.
Overrides FilterInterface::process
See also
\Drupal\filter\FilterProcessResult
File
- src/
Plugin/ Filter/ TokenFilter.php, line 118
Class
- TokenFilter
- Provides a filter that replaces global and entity tokens with their values.
Namespace
Drupal\token_filter\Plugin\FilterCode
public function process($text, $langcode) {
$data = [];
$entity = drupal_static('token_filter_entity', NULL);
$cache = new BubbleableMetadata();
if (!is_null($entity) && $entity instanceof ContentEntityInterface) {
$cache
->addCacheableDependency($entity);
$token_type = $this->tokenEntityMapper
->getTokenTypeForEntityType($entity
->getEntityTypeId());
$data[$token_type] = $entity;
}
$clear = $this->settings['replace_empty'];
$replacements = $this->token
->replace($text, $data, [
'clear' => $clear,
], $cache);
return (new FilterProcessResult($replacements))
->merge($cache);
}