/** * Implements preg_replace_callback() callback. * * @see self::process() */ 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]; }
/** * Implements preg_replace_callback() callback. * * @see self::process() */ function processCallback(array $matches) { $currency_code_from = $matches[1]; $currency_code_to = $matches[2]; $amount = str_replace(':', '', $matches[3]); if (strlen($amount) !== 0) { $amount = $this->input->parseAmount($amount); // The amount is invalid, so return the token. if (!$amount) { return $matches[0]; } } else { $amount = 1; } $exchange_rate = $this->exchangeRateProvider->load($currency_code_from, $currency_code_to); $this->currentFilterProcessResult->addCacheableDependency($exchange_rate); if ($exchange_rate) { return bcmul($amount, $exchange_rate->getRate(), 6); } // No exchange rate could be loaded, so return the token. return $matches[0]; }