You are here

public function OrderUpdateForm::submitForm in Ubercart 8.4

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

uc_order/src/Form/OrderUpdateForm.php, line 113

Class

OrderUpdateForm
Updates an order's status and optionally adds comments.

Namespace

Drupal\uc_order\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $uid = $this
    ->currentUser()
    ->id();
  if (!$form_state
    ->isValueEmpty('order_comment')) {
    uc_order_comment_save($form_state
      ->getValue('order_id'), $uid, $form_state
      ->getValue('order_comment'), 'order', $form_state
      ->getValue('status'), $form_state
      ->getValue('notify'));
  }
  if (!$form_state
    ->isValueEmpty('admin_comment')) {
    uc_order_comment_save($form_state
      ->getValue('order_id'), $uid, $form_state
      ->getValue('admin_comment'));
  }
  if ($form_state
    ->getValue('status') != $form_state
    ->getValue('current_status')) {
    Order::load($form_state
      ->getValue('order_id'))
      ->setStatusId($form_state
      ->getValue('status'))
      ->save();
    if ($form_state
      ->isValueEmpty('order_comment')) {
      uc_order_comment_save($form_state
        ->getValue('order_id'), $uid, '-', 'order', $form_state
        ->getValue('status'), $form_state
        ->getValue('notify'));
    }
  }

  // Let Rules send email if requested.
  if ($form_state
    ->getValue('notify')) {
    $order = Order::load($form_state
      ->getValue('order_id'));

    /* rules_invoke_event('uc_order_status_email_update', $order); */
    $event = new OrderStatusEmailUpdateEvent($order);
    $this->eventDispatcher
      ->dispatch($event::EVENT_NAME, $event);
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('Order updated.'));
}