You are here

public function TaxRateListBuilder::buildForm in Ubercart 8.4

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

File

uc_tax/src/TaxRateListBuilder.php, line 120

Class

TaxRateListBuilder
Provides a listing of tax rate entities.

Namespace

Drupal\uc_tax

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $options = array_map(function ($definition) {
    return $definition['label'];
  }, $this->taxRatePluginManager
    ->getDefinitions());
  uasort($options, 'strnatcasecmp');
  $form['add'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Add a tax rate'),
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $form['add']['plugin'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Type'),
    '#empty_option' => $this
      ->t('- Choose -'),
    '#options' => $options,
  ];
  $form['add']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add tax rate'),
    '#validate' => [
      '::validateAddMethod',
    ],
    '#submit' => [
      '::submitAddMethod',
    ],
    '#limit_validation_errors' => [
      [
        'plugin',
      ],
    ],
  ];
  $form = parent::buildForm($form, $form_state);
  $form[$this->entitiesKey]['#empty'] = $this
    ->t('No tax rates have been configured yet.');
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
    '#button_type' => 'primary',
  ];
  return $form;
}