public function SocialProfilePrivacyHelper::getFieldOptions in Open Social 10.2.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper::getFieldOptions()
- 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper::getFieldOptions()
- 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper::getFieldOptions()
Returns field settings of a user profile.
Parameters
\Drupal\Core\Session\AccountInterface|null $account: (optional) The user session for which to check access, or NULL to check access for the current user. Defaults to NULL.
Return value
array The array of field labels and accesses, keyed by field name.
Overrides SocialProfilePrivacyHelperInterface::getFieldOptions
File
- modules/
social_features/ social_profile/ modules/ social_profile_privacy/ src/ Service/ SocialProfilePrivacyHelper.php, line 50
Class
- SocialProfilePrivacyHelper
- Defines the helper service.
Namespace
Drupal\social_profile_privacy\ServiceCode
public function getFieldOptions(AccountInterface $account = NULL) {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
$display = $this->entityTypeManager
->getStorage('entity_form_display')
->load('profile.profile.default');
$definitions = $this->entityFieldManager
->getFieldDefinitions('profile', 'profile');
$handler = $this->entityTypeManager
->getAccessControlHandler('profile');
if ($account) {
/** @var \Drupal\profile\ProfileStorageInterface $storage */
$storage = $this->entityTypeManager
->getStorage('profile');
$profile = $storage
->loadByUser($account, 'profile');
}
$options = [];
foreach (array_keys($display
->getComponents()) as $field) {
$definition = $definitions[$field];
if ($definition instanceof FieldConfigInterface) {
$items = $account ? $profile
->get($field) : NULL;
$options[$field] = [
'label' => $definition
->label(),
'access' => $handler
->fieldAccess('edit', $definition, $account, $items),
];
}
}
return $options;
}