You are here

public function TokenVarConfig::buildForm in Token Variable 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/Form/TokenVarConfig.php, line 38

Class

TokenVarConfig
Implements TokenVarConfig class.

Namespace

Drupal\token_var\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = \Drupal::config('token_var.settings')
    ->get('token_var_replacements');

  // TODO: Change the autogenerated stub.
  $form = parent::buildForm($form, $form_state);
  $form['#tree'] = TRUE;
  foreach ($this->configFactory
    ->listAll() as $name) {
    $form['token_var'][$name] = array(
      '#type' => 'details',
      '#title' => $name,
    );
    foreach ($this->configFactory
      ->get($name)
      ->getRawData() as $key => $value) {
      if (!is_array($value) && !is_object($value)) {
        $default_value = isset($config[str_replace('.', '|', $name)][$key]) ? 1 : 0;
        $form['token_var'][$name][$key] = array(
          '#type' => 'checkbox',
          '#title' => $key,
          '#default_value' => $default_value,
        );
      }
    }
  }
  return $form;
}