You are here

public function MaskedInputSettingsForm::buildForm in Masked Input 8

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 ConfigFormBase::buildForm

File

src/MaskedInputSettingsForm.php, line 40

Class

MaskedInputSettingsForm
provides Configure settings.

Namespace

Drupal\masked_input

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('masked_input.settings');
  $definitions = $config
    ->get('masked_input_definitions');
  $definitions_count = count($definitions) + 1;
  $form['definition'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Mask Definitions'),
  );
  $form['definition']['definitions'] = array(
    '#type' => 'table',
    '#prefix' => '<div id="masked_input-definitions">',
    '#suffix' => '</div>',
    '#tree' => TRUE,
  );
  for ($i = 0; $i < $definitions_count; $i++) {
    $form['definition']['definitions'][$i] = _maskinput_definitions_element($i, $definitions);
  }
  $form['definition']['add_another_definition'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Add another'),
    '#submit' => array(
      '_masked_input_definitions_add_another_submit',
    ),
    '#ajax' => array(
      'callback' => '_masked_input_definitions_add_another_callback',
      'wrapper' => 'masked_input-definitions',
    ),
  );
  return parent::buildForm($form, $form_state);
}