You are here

public function ConditionalFieldsFormHelper::afterBuild in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/ConditionalFieldsFormHelper.php \Drupal\conditional_fields\ConditionalFieldsFormHelper::afterBuild()

An after_build callback for forms with dependencies.

Builds and attaches #states properties to dependent fields, adds additional visual effects handling to the States API and attaches a validation callback to the form that handles validation of dependent fields.

Parameters

array $form: The form array being modified.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the form being modified.

Return value

array The modified form array.

File

src/ConditionalFieldsFormHelper.php, line 80

Class

ConditionalFieldsFormHelper
Helper to interact with forms.

Namespace

Drupal\conditional_fields

Code

public function afterBuild(array $form, FormStateInterface &$form_state) {
  $this->form = $form;
  $this->form_state = $form_state;
  if ($this
    ->hasConditionalFields()) {
    $this
      ->processDependentFields()
      ->addJavascriptEffects()
      ->addValidationCallback();
  }
  return $this->form;
}