public function FixedRates::save in Currency 8.3
Saves an exchange rate.
Parameters
string $currency_code_from:
string $currency_code_to:
string $rate:
Return value
$this
File
- src/
Plugin/ Currency/ ExchangeRateProvider/ FixedRates.php, line 77
Class
- FixedRates
- Provides manually entered exchange rates.
Namespace
Drupal\currency\Plugin\Currency\ExchangeRateProviderCode
public function save($currency_code_from, $currency_code_to, $rate) {
$config = $this->configFactory
->getEditable('currency.exchanger.fixed_rates');
$rates = $this
->loadAll();
$rates[$currency_code_from][$currency_code_to] = $rate;
// Massage the rates into a format that can be stored, as associative
// arrays are not supported by the config system
$rates_data = array();
foreach ($rates as $currency_code_from => $currency_code_from_rates) {
foreach ($currency_code_from_rates as $currency_code_to => $rate) {
$rates_data[] = array(
'currency_code_from' => $currency_code_from,
'currency_code_to' => $currency_code_to,
'rate' => $rate,
);
}
}
$config
->set('rates', $rates_data);
$config
->save();
return $this;
}