class SocialProfilePrivacyHelper in Open Social 10.0.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
- 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper
- 10.2.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper
Defines the helper service.
@package Drupal\social_profile_privacy\Service
Hierarchy
- class \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper implements SocialProfilePrivacyHelperInterface
Expanded class hierarchy of SocialProfilePrivacyHelper
1 string reference to 'SocialProfilePrivacyHelper'
- social_profile_privacy.services.yml in modules/
social_features/ social_profile/ modules/ social_profile_privacy/ social_profile_privacy.services.yml - modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.services.yml
1 service uses SocialProfilePrivacyHelper
- social_profile_privacy.helper in modules/
social_features/ social_profile/ modules/ social_profile_privacy/ social_profile_privacy.services.yml - Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper
File
- modules/
social_features/ social_profile/ modules/ social_profile_privacy/ src/ Service/ SocialProfilePrivacyHelper.php, line 15
Namespace
Drupal\social_profile_privacy\ServiceView source
class SocialProfilePrivacyHelper implements SocialProfilePrivacyHelperInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* SocialProfilePrivacyHelper constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialProfilePrivacyHelper:: |
protected | property | The entity field manager. | |
SocialProfilePrivacyHelper:: |
protected | property | The entity type manager. | |
SocialProfilePrivacyHelper:: |
public | function |
Returns field settings of a user profile. Overrides SocialProfilePrivacyHelperInterface:: |
|
SocialProfilePrivacyHelper:: |
public | function | SocialProfilePrivacyHelper constructor. | |
SocialProfilePrivacyHelperInterface:: |
constant | Show profile field, but it can be hidden by a user. | ||
SocialProfilePrivacyHelperInterface:: |
constant | Hide profile field for everyone. | ||
SocialProfilePrivacyHelperInterface:: |
constant | Always show profile field for everyone. |