You are here

public function SelectRegistrationConfigForm::buildForm in Select registration roles 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/SelectRegistrationConfigForm.php, line 39
Contains \Drupal\select_registration_roles\Form\SelectRegistrationConfigForm.

Class

SelectRegistrationConfigForm

Namespace

Drupal\select_registration_roles\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('select_registration_roles.settings');

  //$roles = select_registration_roles_get_all_roles();
  $default_value = array();
  $roles = select_registration_roles_all_roles(true);
  if ($config
    ->get('select_registration_roles_setby_admin')) {
    $value_select_registration_roles_setby_admin = $config
      ->get('select_registration_roles_setby_admin');
  }
  else {
    $value_select_registration_roles_setby_admin = $default_value;
  }
  $form['select_registration_roles_setby_admin'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Roles'),
    '#options' => $roles,
    '#description' => t("Select roles that will be displayed on registration form"),
    '#default_value' => $value_select_registration_roles_setby_admin,
  );
  $roles = select_registration_roles_all_roles(true);
  if ($config
    ->get('select_registration_roles_admin_approval')) {
    $value_select_registration_roles_admin_approval = $config
      ->get('select_registration_roles_admin_approval');
  }
  else {
    $value_select_registration_roles_admin_approval = $default_value;
  }
  $form['select_registration_roles_admin_approval'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Approval Roles'),
    '#options' => $roles,
    '#description' => t("Select roles that need admin approval"),
    '#default_value' => $value_select_registration_roles_admin_approval,
  );
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
    '#button_type' => 'primary',
  );

  // By default, render the form using theme_system_config_form().
  $form['#theme'] = 'system_config_form';
  return $form;
}