You are here

public function FormWizardBase::buildForm in Chaos Tool Suite (ctools) 8.3

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

src/Wizard/FormWizardBase.php, line 245

Class

FormWizardBase
The base class for all form wizard.

Namespace

Drupal\ctools\Wizard

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  // Get the current form operation.
  $operation = $this
    ->getOperation($cached_values);
  $form = $this
    ->customizeForm($form, $form_state);

  /* @var $formClass \Drupal\Core\Form\FormInterface */
  $formClass = $this->classResolver
    ->getInstanceFromDefinition($operation['form']);

  // Pass include any custom values for this operation.
  if (!empty($operation['values'])) {
    $cached_values = array_merge($cached_values, $operation['values']);
    $form_state
      ->setTemporaryValue('wizard', $cached_values);
  }

  // Build the form.
  $form = $formClass
    ->buildForm($form, $form_state);
  if (isset($operation['title'])) {
    $form['#title'] = $operation['title'];
  }
  $form['actions'] = $this
    ->actions($formClass, $form_state);
  return $form;
}