You are here

public function PCPForm::buildForm in Profile Complete Percent 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/PCPForm.php, line 64

Class

PCPForm
Provides a PCP configuration form.

Namespace

Drupal\pcp\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('pcp.settings');
  $form['general_setting'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('General Setting'),
  ];
  $form['general_setting']['hide_pcp_block_on_complete'] = [
    '#type' => 'checkbox',
    '#option' => [
      '1',
    ],
    '#default_value' => $config
      ->get('hide_block_on_complete'),
    '#title' => $this
      ->t('Hide Block When Complete.'),
    '#description' => $this
      ->t('When a user reaches 100% complete of their profile, do you want the profile complete percent block to go away? If so, check this box on.'),
  ];
  $form['general_setting']['field_order'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Profile Fields Order'),
    '#options' => [
      '0' => $this
        ->t('Random'),
      '1' => $this
        ->t('Fixed'),
    ],
    '#default_value' => $config
      ->get('field_order') ?: 0,
    '#description' => $this
      ->t('Select to show which field come first.'),
  ];
  $form['general_setting']['open_field_link'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Profile Fields Open Link'),
    '#options' => [
      '0' => $this
        ->t('Same Window'),
      '1' => $this
        ->t('New Window'),
    ],
    '#default_value' => $config
      ->get('open_link') ?: 0,
    '#description' => $this
      ->t('Select to open field link in browser.'),
  ];
  $form['core_field_setting'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Core Profile Field Settings'),
  ];
  $fields = array_filter($this->entityFieldManager
    ->getFieldDefinitions('user', 'user'), function ($field_definition) {
    return $field_definition instanceof FieldConfigInterface;
  });
  $user_field = [];
  foreach ($fields as $key => $value) {

    // TODO Check/fix loading field labels in the right language.
    $user_field[$key] = $fields[$key]
      ->label();
  }
  $form['core_field_setting']['profile_fields'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Profile Fields'),
    '#options' => $user_field,
    '#default_value' => $config
      ->get('profile_fields') ?: [],
    '#description' => $this
      ->t('Checking a profile field below will add that field to the logic of the complete percentage.'),
  ];
  return parent::buildForm($form, $form_state);
}