/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Skip building the form if there are no available stores. $store_query = $this->storeStorage->getQuery(); if ($store_query->count()->execute() == 0) { $options = ['query' => ['destination' => Url::fromRoute('<current>')->toString()]]; $link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page', [], $options); $form['warning'] = ['#markup' => t("Orders can't be created until a store has been added. @link", ['@link' => $link->toString()])]; return $form; } $form['type'] = ['#type' => 'commerce_entity_select', '#title' => $this->t('Order type'), '#target_type' => 'commerce_order_type', '#required' => TRUE]; $form['store_id'] = ['#type' => 'commerce_entity_select', '#title' => $this->t('Store'), '#target_type' => 'commerce_store', '#required' => TRUE]; $form = $this->buildCustomerForm($form, $form_state); $form['custom_placed_date'] = ['#type' => 'checkbox', '#title' => $this->t('Place the order on a different date'), '#default_value' => FALSE]; // The datetime element needs to be wrapped in order for #states to work // properly. See https://www.drupal.org/node/2419131 $form['placed_wrapper'] = ['#type' => 'container', '#states' => ['visible' => [':input[name="custom_placed_date"]' => ['checked' => TRUE]]]]; $form['placed_wrapper']['placed'] = ['#type' => 'datetime', '#title_display' => 'invisible', '#title' => $this->t('Placed'), '#default_value' => new DrupalDateTime()]; $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Create'), '#button_type' => 'primary']; return $form; }