function social_profile_fields_entity_bundle_field_info_alter in Open Social 8.9
Same name and namespace in other branches
- 8.7 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
- 8.8 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
- 10.3.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
- 10.0.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
- 10.1.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
- 10.2.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_entity_bundle_field_info_alter()
Implements hook_entity_bundle_field_info_alter().
File
- modules/
social_features/ social_profile/ modules/ social_profile_fields/ social_profile_fields.module, line 242 - The social profile fields module file.
Code
function social_profile_fields_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if ($bundle === 'profile' && $entity_type
->id() === 'profile') {
$config = \Drupal::config('social_profile_fields.settings');
// Add the unique nickname constraint.
if (isset($fields['field_profile_nick_name']) && $config
->get('nickname_unique_validation')) {
$fields['field_profile_nick_name']
->addConstraint('UniqueNickname', []);
}
// Change address fields override settings.
if (isset($fields['field_profile_address'])) {
$field_profile_address = $fields['field_profile_address'];
if ($setting = $field_profile_address
->getSetting('fields')) {
$setting['locality'] = !$config
->get('profile_address_field_city') ? '0' : 'locality';
$setting['addressLine1'] = !$config
->get('profile_address_field_address') ? '0' : 'addressLine1';
$setting['postalCode'] = !$config
->get('profile_address_field_postalcode') ? '0' : 'postalCode';
// Update the settings of address field.
$fields['field_profile_address']
->setSetting('fields', $setting);
}
elseif ($setting = $field_profile_address
->getSetting('field_overrides')) {
if (!$config
->get('profile_address_field_city')) {
$setting['locality'] = [
'override' => 'hidden',
];
}
else {
unset($setting['locality']);
}
if (!$config
->get('profile_address_field_address')) {
$setting['addressLine1'] = [
'override' => 'hidden',
];
}
else {
unset($setting['addressLine1']);
}
if (!$config
->get('profile_address_field_postalcode')) {
$setting['postalCode'] = [
'override' => 'hidden',
];
}
else {
unset($setting['postalCode']);
}
// Update the settings of address field.
$fields['field_profile_address']
->setSetting('field_overrides', $setting);
}
}
}
}