You are here

public function OrderForm::form in Ubercart 8.4

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

uc_order/src/OrderForm.php, line 51

Class

OrderForm
Form controller for the Ubercart order form.

Namespace

Drupal\uc_order

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\uc_order\OrderInterface $order */
  $order = $this->entity;
  $form['#order'] = $order;
  $form['order_modified'] = [
    '#type' => 'value',
    '#value' => $form_state
      ->getValue('order_modified') ?: $order
      ->getChangedTime(),
  ];
  $panes = $this->orderPaneManager
    ->getPanes();
  $components = $this
    ->getFormDisplay($form_state)
    ->getComponents();
  foreach ($panes as $id => $pane) {
    if ($pane instanceof EditableOrderPanePluginInterface) {
      $form[$id] = $pane
        ->buildForm($order, [], $form_state);
      $form[$id]['#prefix'] = '<div class="order-pane ' . implode(' ', $pane
        ->getClasses()) . '" id="order-pane-' . $id . '">';
      if ($title = $pane
        ->getTitle()) {
        $form[$id]['#prefix'] .= '<div class="order-pane-title">' . $title . ':' . '</div>';
      }
      $form[$id]['#suffix'] = '</div>';
      $form[$id]['#weight'] = $components[$id]['weight'];
    }
  }
  $form = parent::form($form, $form_state);
  $form['#process'][] = [
    $this,
    'ajaxProcessForm',
  ];
  return $form;
}