You are here

class SocialProfilePrivacyHelper in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper
  2. 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/src/Service/SocialProfilePrivacyHelper.php \Drupal\social_profile_privacy\Service\SocialProfilePrivacyHelper
  3. 10.1.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

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\Service
View 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

Namesort descending Modifiers Type Description Overrides
SocialProfilePrivacyHelper::$entityFieldManager protected property The entity field manager.
SocialProfilePrivacyHelper::$entityTypeManager protected property The entity type manager.
SocialProfilePrivacyHelper::getFieldOptions public function Returns field settings of a user profile. Overrides SocialProfilePrivacyHelperInterface::getFieldOptions
SocialProfilePrivacyHelper::__construct public function SocialProfilePrivacyHelper constructor.
SocialProfilePrivacyHelperInterface::CONFIGURABLE constant Show profile field, but it can be hidden by a user.
SocialProfilePrivacyHelperInterface::HIDE constant Hide profile field for everyone.
SocialProfilePrivacyHelperInterface::SHOW constant Always show profile field for everyone.