You are here

public function SocialProfileFieldsSettingsForm::buildForm in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  2. 8.2 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  3. 8.3 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  4. 8.4 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  5. 8.5 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  6. 8.6 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  7. 8.8 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  8. 10.3.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  9. 10.0.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  10. 10.1.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
  11. 10.2.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()

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

modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php, line 113

Class

SocialProfileFieldsSettingsForm
Configure social profile settings.

Namespace

Drupal\social_profile_fields\Form

Code

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

  // Add an introduction text to explain what can be done here.
  $form['introduction']['description'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Per profile type you can choose which fields you want to use. Users will not be able to edit or view fields that are deselected.'),
  ];
  $form['introduction']['warning'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Be aware that data is <em>not removed</em>, and can possibly still be found through the search, until you flush the data.'),
  ];

  /** @var \Drupal\profile\Entity\ProfileType $profile_type */
  foreach (ProfileType::loadMultiple() as $profile_type) {
    $type = $profile_type
      ->id();
    $form[$type] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Settings for profiletype: @profile_type', [
        '@profile_type' => $type,
      ]),
      '#description' => $this
        ->t('Select the fields you want to use on this profile type.'),
      '#open' => TRUE,
    ];

    /** @var \Drupal\field\Entity\FieldConfig $field_config */
    foreach ($this->profileFieldsHelper
      ->getProfileFields($type) as $field) {

      // Loop through the fields.
      $id = $field['id'];

      // Hiding this field on the Open Social profile will make no difference,
      // let's skip it for now.
      if ($type === 'profile' && $id === 'profile_profile_field_profile_show_email') {
        continue;
      }

      // No setting is TRUE.
      $default_value = is_null($config
        ->get($id)) ? TRUE : $config
        ->get($id);
      $form[$type][$id] = [
        '#type' => 'checkbox',
        '#title' => $field['label'],
        '#description' => $field['name'],
        '#default_value' => $default_value,
      ];
    }
  }
  $form['nickname_unique_validation'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Unique nicknames'),
    '#description' => $this
      ->t('If you check this, validation is applied that verifies the users nickname is unique whenever they save their profile.'),
    '#default_value' => $config
      ->get('nickname_unique_validation'),
  ];
  $form['actions']['social_profile_fields_confirm_flush'] = [
    '#type' => 'submit',
    '#submit' => [
      '::submitFlush',
    ],
    '#value' => $this
      ->t('Flush profile data'),
    '#weight' => 5,
  ];
  return parent::buildForm($form, $form_state);
}