public function CheckoutFlowBase::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
1 call to CheckoutFlowBase::buildForm()
- CheckoutFlowWithPanesBase::buildForm in modules/
checkout/ src/ Plugin/ Commerce/ CheckoutFlow/ CheckoutFlowWithPanesBase.php - Form constructor.
1 method overrides CheckoutFlowBase::buildForm()
- CheckoutFlowWithPanesBase::buildForm in modules/
checkout/ src/ Plugin/ Commerce/ CheckoutFlow/ CheckoutFlowWithPanesBase.php - Form constructor.
File
- modules/
checkout/ src/ Plugin/ Commerce/ CheckoutFlow/ CheckoutFlowBase.php, line 344
Class
- CheckoutFlowBase
- Provides the base checkout flow class.
Namespace
Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlowCode
public function buildForm(array $form, FormStateInterface $form_state, $step_id = NULL) {
// The $step_id argument is optional only because PHP disallows adding
// required arguments to an existing interface's method.
if (empty($step_id)) {
throw new \InvalidArgumentException('The $step_id cannot be empty.');
}
if ($form_state
->isRebuilding()) {
// Ensure a fresh order, in case an ajax submit has modified it.
$order_storage = $this->entityTypeManager
->getStorage('commerce_order');
$this->order = $order_storage
->load($this->order
->id());
}
$steps = $this
->getSteps();
$form['#tree'] = TRUE;
$form['#step_id'] = $step_id;
$form['#title'] = $steps[$step_id]['label'];
$form['#theme'] = [
'commerce_checkout_form',
];
$form['#attached']['library'][] = 'commerce_checkout/form';
// Workaround for core bug #2897377.
$form['#id'] = Html::getId($form_state
->getBuildInfo()['form_id']);
if ($this
->hasSidebar($step_id)) {
$form['sidebar']['order_summary'] = [
'#theme' => 'commerce_checkout_order_summary',
'#order_entity' => $this->order,
'#checkout_step' => $step_id,
];
}
$form['actions'] = $this
->actions($form, $form_state);
// Make sure the cache is removed if the parent entity or the order change.
CacheableMetadata::createFromRenderArray($form)
->addCacheableDependency($this->parentEntity)
->addCacheableDependency($this->order)
->applyTo($form);
return $form;
}