public function SocialProfileFieldsSettingsForm::buildForm in Open Social 10.0.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.2 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.3 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.4 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.5 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.6 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.7 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 8.8 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 10.3.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 10.1.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsSettingsForm::buildForm()
- 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 133
Class
- SocialProfileFieldsSettingsForm
- Configure social profile settings.
Namespace
Drupal\social_profile_fields\FormCode
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,
];
if ($type === 'profile' && $id === 'profile_profile_field_profile_address') {
$form[$type]['profile_profile_field_profile_address_wrapper'][$id] = $form[$type][$id];
unset($form[$type][$id]);
$form[$type]['profile_profile_field_profile_address_wrapper']['address_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Individual address field settings'),
'#open' => TRUE,
'#states' => [
'visible' => [
':input[name="' . $id . '"]' => [
'checked' => TRUE,
],
],
],
];
$form[$type]['profile_profile_field_profile_address_wrapper']['address_settings']['profile_address_field_country'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('You can hide individual address fields, with the exception of the country field. <br/>
Disable the country field by disabling the whole address, using the checkbox <em>field_profile_address</em>.'),
];
$form[$type]['profile_profile_field_profile_address_wrapper']['address_settings']['profile_address_field_city'] = [
'#type' => 'checkbox',
'#title' => $this
->t('City'),
'#default_value' => is_null($config
->get('profile_address_field_city')) ? TRUE : $config
->get('profile_address_field_city'),
];
$form[$type]['profile_profile_field_profile_address_wrapper']['address_settings']['profile_address_field_address'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Address'),
'#default_value' => is_null($config
->get('profile_address_field_address')) ? TRUE : $config
->get('profile_address_field_address'),
];
$form[$type]['profile_profile_field_profile_address_wrapper']['address_settings']['profile_address_field_postalcode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Postal code'),
'#default_value' => is_null($config
->get('profile_address_field_postalcode')) ? TRUE : $config
->get('profile_address_field_postalcode'),
];
}
}
}
$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);
}