You are here

public function AddressBookForm::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 FormInterface::buildForm

File

uc_order/src/Form/AddressBookForm.php, line 23

Class

AddressBookForm
Presents previously entered addresses as selectable options.

Namespace

Drupal\uc_order\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $uid = 0, $type = 'billing', $func = '') {
  $select = uc_select_address($uid, $type, $func);
  if ($uid == 0) {
    $form['desc'] = [
      '#prefix' => '<br />',
      '#markup' => $this
        ->t('You must select a customer before address<br />information is available.<br />'),
      '#suffix' => '<br />',
    ];
  }
  elseif (is_null($select)) {
    $form['desc'] = [
      '#prefix' => '<br />',
      '#markup' => $this
        ->t('No addresses found for customer.'),
      '#suffix' => '<br />',
    ];
  }
  else {
    $form['addresses'] = uc_select_address($uid, $type, $func, $this
      ->t('Select an address'));

    // @todo Remove the CSS, put into uc_order.css
    $form['addresses']['#prefix'] = '<div style="float: left; margin-right: 1em;">';
    $form['addresses']['#suffix'] = '</div>';
  }

  // Need to pass along address type selector for use in the JavaScript.
  $form['#attached']['drupalSettings']['addressTypeId'] = '#' . $type . '-address-select';
  $form['close'] = [
    '#type' => 'button',
    '#value' => $this
      ->t('Close'),
    '#attributes' => [
      'id' => 'close-address-select',
    ],
  ];
  return $form;
}