You are here

public function OrderReassignForm::buildForm in Commerce Core 8.2

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

modules/order/src/Form/OrderReassignForm.php, line 77

Class

OrderReassignForm
Provides a form for assigning orders to a different customer.

Namespace

Drupal\commerce_order\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $customer = $this->order
    ->getCustomer();
  if ($customer
    ->isAnonymous()) {
    $current_customer = $this
      ->t('anonymous user with the email %email', [
      '%email' => $this->order
        ->getEmail(),
    ]);
  }
  else {

    // If the display name has been altered to not be the email address,
    // show the email as well.
    if ($customer
      ->getDisplayName() != $customer
      ->getEmail()) {
      $customer_link_text = $this
        ->t('@display (@email)', [
        '@display' => $customer
          ->getDisplayName(),
        '@email' => $customer
          ->getEmail(),
      ]);
    }
    else {
      $customer_link_text = $customer
        ->getDisplayName();
    }
    $current_customer = $this->order
      ->getCustomer()
      ->toLink($customer_link_text)
      ->toString();
  }
  $form['current_customer'] = [
    '#type' => 'item',
    '#markup' => $this
      ->t('The order is currently assigned to @customer.', [
      '@customer' => $current_customer,
    ]),
  ];
  $form += $this
    ->buildCustomerForm($form, $form_state, $this->order);
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Reassign order'),
    '#button_type' => 'primary',
  ];
  return $form;
}