function CurrencyLocalize::processCallback in Currency 8.3
Implements preg_replace_callback() callback.
See also
File
- src/
Plugin/ Filter/ CurrencyLocalize.php, line 96
Class
- CurrencyLocalize
- Provides a filter to format amounts.
Namespace
Drupal\currency\Plugin\FilterCode
function processCallback(array $matches) {
$currency_code = $matches[1];
$amount = $this->input
->parseAmount($matches[2]);
// The amount is invalid, so return the token.
if (!$amount) {
return $matches[0];
}
/** @var \Drupal\currency\Entity\CurrencyInterface $currency */
$currency = $this->currencyStorage
->load($currency_code);
$this->currentFilterProcessResult
->addCacheableDependency($currency);
if ($currency) {
return $currency
->formatAmount($amount);
}
// The currency code is invalid, so return the token.
return $matches[0];
}