public function MultistepController::rebuildForm in Simple multi step form 8.x
Same name and namespace in other branches
- 8 src/MultistepController.php \Drupal\simple_multistep\MultistepController::rebuildForm()
Prepare Multistep Form.
Parameters
array $form: Reference to form.
File
- src/
MultistepController.php, line 98
Class
- MultistepController
- Class MultistepController.
Namespace
Drupal\simple_multistepCode
public function rebuildForm(array &$form) {
// Add step indicator.
$this->stepIndicator = new StepIndicator($form, $this->formState, $this->currentStep);
$this->stepIndicator
->render($form);
unset($form['actions']['next']['#limit_validation_errors']);
foreach ($this->steps as $key => $step) {
$all_children = $this
->getAllChildren($step);
if (!empty($all_children)) {
// Another step.
if ($key != $this->currentStep) {
foreach ($all_children as $child_id) {
if (isset($form[$child_id])) {
$form[$child_id]['#access'] = FALSE;
}
}
}
else {
foreach ($all_children as $child_id) {
if (isset($form[$child_id])) {
$form['actions']['next']['#limit_validation_errors'][] = array(
$child_id,
);
}
}
}
}
}
// Last step.
if ($this->currentStep == count($this->steps) - 1) {
foreach ($form as $element_key => $form_element) {
if (is_array($form_element) && isset($form_element['#type'])) {
if (isset($form['actions']['next']['#limit_validation_errors'])) {
unset($form['actions']['next']['#limit_validation_errors']);
}
}
}
}
// Add additional button for form.
$this->formButton = new FormButton($form, $this->formState, $this->currentStep);
$this->formButton
->render($form);
}