You are here

public function CurrencyImportForm::buildForm in Price 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/CurrencyImportForm.php \Drupal\price\Form\CurrencyImportForm::buildForm()
  2. 3.x src/Form/CurrencyImportForm.php \Drupal\price\Form\CurrencyImportForm::buildForm()
  3. 2.x src/Form/CurrencyImportForm.php \Drupal\price\Form\CurrencyImportForm::buildForm()
  4. 3.0.x src/Form/CurrencyImportForm.php \Drupal\price\Form\CurrencyImportForm::buildForm()

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 FormInterface::buildForm

File

src/Form/CurrencyImportForm.php, line 49

Class

CurrencyImportForm
Provides a form for importing currencies from library definitions.

Namespace

Drupal\price\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $currencies = $this->importer
    ->getImportable();
  if (empty($currencies)) {
    $form['message'] = [
      '#markup' => $this
        ->t('All currencies have already been imported.'),
    ];
  }
  else {
    $form['currency_codes'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Available currencies'),
      '#options' => $currencies,
      '#multiple' => TRUE,
      '#size' => 10,
    ];
    $form['actions']['#type'] = 'actions';
    $form['actions']['import'] = [
      '#type' => 'submit',
      '#button_type' => 'primary',
      '#name' => 'import',
      '#value' => $this
        ->t('Add'),
      '#submit' => [
        '::submitForm',
      ],
    ];
  }
  return $form;
}