Commit 6974cc17 authored by Ray Yick's avatar Ray Yick
Browse files

Issue #3057680: resolved issues listed by klausi

parent 137baee3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class ExchangeRatesBlockForm.
 * Form that displays Exchange Rates block.
 */
class ExchangeRatesBlockForm extends FormBase {
  /**
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Class ExchangeRatesSettingsForm.
 * Config form to set base and conversion currencies.
 */
class ExchangeRatesSettingsForm extends ConfigFormBase {

@@ -182,7 +182,7 @@ class ExchangeRatesSettingsForm extends ConfigFormBase {
    $config->save();

    // Confirmation on form submission.
    drupal_set_message($this->t('The Exchange Rates settings have been saved.'));
    $this->messenger()->addStatus($this->t('The Exchange Rates settings have been saved.'));
  }

}
+7 −5
Original line number Diff line number Diff line
@@ -106,12 +106,14 @@ class ExchangeRatesBlock extends BlockBase implements ContainerFactoryPluginInte
    $conversion_currencies = $config->get('conversion_currency');

    // exchangeratesapi.io API call to fetch exchange rates for base currency.
    try {
      $response = json_decode($this->httpClient->get('https://api.exchangeratesapi.io/latest?base=' . $base_currency)->getBody());
    $rates = [];

    if (!empty($response) && !empty($response->rates)) {
      $rates = $response->rates;
    }
    catch (RequestException $e) {
      watchdog_exception('exchange_rates', $e->getMessage());
    }

    $rates = (!empty($response) && !empty($response->rates)) ? $response->rates : [];

    // Store conversion currency rates in state.
    foreach ($rates as $conversion_currency => $rate) {