function social_profile_form_user_form_alter in Open Social 8.9
Same name and namespace in other branches
- 8 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.2 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.3 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.4 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.5 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.6 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.7 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 8.8 modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 10.3.x modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 10.0.x modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 10.1.x modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
- 10.2.x modules/social_features/social_profile/social_profile.module \social_profile_form_user_form_alter()
Implements hook_form_FORM_ID_alter() for user_form().
File
- modules/
social_features/ social_profile/ social_profile.module, line 528 - The Social profile module.
Code
function social_profile_form_user_form_alter(&$form, FormStateInterface $form_state) {
$profile = _social_profile_get_profile_from_route();
if ($profile instanceof Profile) {
// @TODO: Move privacy settings to a separate entity.
// Check what the global value is.
$social_profile_settings_config = \Drupal::config('social_profile.settings');
$global_values = [
'social_profile_show_email' => $social_profile_settings_config
->get('social_profile_show_email'),
];
// Account values.
$show_email = $profile->field_profile_show_email->value;
$form['profile_privacy'] = [
'#type' => 'fieldset',
'#title' => t('Privacy settings'),
'#tree' => TRUE,
];
$form['profile_privacy']['social_profile_show_email'] = [
'#type' => 'checkbox',
'#title' => t('Show my email on my profile'),
'#default_value' => $show_email,
'#attributes' => [
'data-switch' => TRUE,
],
];
$is_multilingual = \Drupal::languageManager()
->isMultilingual();
if ($is_multilingual) {
$user_data = \Drupal::service('user.data');
$lang_info = $user_data
->get('social_profile_privacy', $profile
->get('uid')->target_id, 'lang_info');
$global_values['social_profile_show_language'] = $social_profile_settings_config
->get('social_profile_show_language');
$form['profile_privacy']['social_profile_show_language'] = [
'#type' => 'checkbox',
'#title' => t('Show my language on my profile'),
'#default_value' => $lang_info,
'#attributes' => [
'data-switch' => TRUE,
],
];
}
// If global setting is set, disable the setting and give a reason why.
foreach ($global_values as $key => $value) {
if ($value && ($key == 'social_profile_show_language' && $is_multilingual || $key == 'social_profile_show_email')) {
$form['profile_privacy']["{$key}"]['#disabled'] = TRUE;
$form['profile_privacy']["{$key}"]['#value'] = TRUE;
$form['profile_privacy']["{$key}"]['#description'] = t('This setting is currently being controlled by a platform wide setting and cannot be changed. Please contact a sitemanager if you have questions.');
}
}
// Add Submit function only when the data is actually editable.
if (empty($global_value['social_profile_show_email']) || empty($global_value['social_profile_show_language'])) {
$form['actions']['submit']['#submit'][] = '_social_profile_form_user_form_submit';
}
}
$form['#pre_render'][] = '_social_profile_form_pre_render';
}