You are here

public function ExchangeRatesForm::buildForm in Commerce Exchanger 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/ExchangeRatesForm.php, line 70

Class

ExchangeRatesForm
Class ExchangeRateForm.

Namespace

Drupal\commerce_exchanger\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  if (empty($this->pluginManager
    ->getDefinitions())) {
    $form['warning'] = [
      '#markup' => $this
        ->t('No  exchange rates plugins found. Please install a module which provides one.'),
    ];
    return $form;
  }

  // Load currencies.
  $currencies = $this->currencyStorage
    ->loadMultiple();

  // If there is now two currencies enabled, do not allow saving.
  if (count($currencies) < 2) {
    $form['warning'] = [
      '#markup' => $this
        ->t('Minimum of two currencies needs to be enabled, to be able to add exchange rates'),
    ];
    return $form;
  }
  return parent::buildForm($form, $form_state);
}