You are here

public function HackedSettingsForm::buildForm in Hacked! 8.2

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/HackedSettingsForm.php, line 30

Class

HackedSettingsForm
Configure locale settings for this site.

Namespace

Drupal\hacked\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('hacked.settings');
  $hashers = hacked_get_file_hashers();
  $form['selected_file_hasher'] = array(
    '#type' => 'details',
    '#title' => t('File hasher'),
    '#open' => TRUE,
  );
  $parents = array(
    'selected_file_hasher',
  );
  foreach ($hashers as $name => $hasher_info) {

    // Generate the parents as the autogenerator does, so we will have a
    // unique id for each radio button.
    $parents_for_id = array_merge($parents, array(
      $name,
    ));
    $form['selected_file_hasher'][$name] = array(
      '#type' => 'radio',
      '#title' => $hasher_info['name'],
      '#default_value' => $config
        ->get('selected_file_hasher'),
      '#return_value' => $name,
      '#parents' => $parents,
      '#description' => !empty($hasher_info['description']) ? $hasher_info['description'] : '',
      '#id' => Html::getId('edit-' . implode('-', $parents_for_id)),
    );
  }
  return parent::buildForm($form, $form_state);
}