Skip to content

Commit

Permalink
Rework the Nickname and Unique Nickanem fields at Profile Fields Sett…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
vcsvinicius authored and robertragas committed Aug 5, 2024
1 parent 67a0471 commit 9ebe447
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,29 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => is_null($config->get('profile_address_field_administrative_area')) ? TRUE : $config->get('profile_address_field_administrative_area'),
];
}

if ($type === 'profile' && $id === 'profile_profile_field_profile_nick_name') {
$form[$type]['profile_profile_nickname_wrapper']['nickname_settings'] = [
'#type' => 'details',
'#title' => $this->t('Nickname field settings'),
'#open' => TRUE,
'#states' => [
'visible' => [
':input[name="' . $id . '"]' => ['checked' => TRUE],
],
],
];

$form[$type]['profile_profile_nickname_wrapper']['nickname_settings']['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['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'],
Expand Down Expand Up @@ -262,7 +275,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$config->set('profile_address_field_postalcode', $main_address_value ? $form_state->getValue('profile_address_field_postalcode') : FALSE);
$config->set('profile_address_field_administrative_area', $main_address_value ? $form_state->getValue('profile_address_field_administrative_area') : FALSE);

$config->set('nickname_unique_validation', $form_state->getValue('nickname_unique_validation'));
$nickname_unique_validation = $form_state->getValue('profile_profile_field_profile_nick_name') ? $form_state->getValue('nickname_unique_validation') : FALSE;
$config->set('nickname_unique_validation', $nickname_unique_validation);
$config->save();

parent::submitForm($form, $form_state);
Expand Down

0 comments on commit 9ebe447

Please sign in to comment.