You are here

public function ConditionalFieldsFormHelper::afterBuild in Conditional Fields 8

Same name and namespace in other branches
  1. 4.x 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.

File

src/ConditionalFieldsFormHelper.php, line 46

Class

ConditionalFieldsFormHelper
Helper to interact with forms.

Namespace

Drupal\conditional_fields

Code

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