You are here

function _social_profile_check_property_access in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/social_profile.module \_social_profile_check_property_access()
  2. 10.3.x modules/social_features/social_profile/social_profile.module \_social_profile_check_property_access()
  3. 10.0.x modules/social_features/social_profile/social_profile.module \_social_profile_check_property_access()
  4. 10.1.x modules/social_features/social_profile/social_profile.module \_social_profile_check_property_access()
  5. 10.2.x modules/social_features/social_profile/social_profile.module \_social_profile_check_property_access()

Helps determine if current user has access to view the property of user.

Parameters

\Drupal\profile\Entity\Profile $profile: The profile the current user is viewing.

\Drupal\Core\Session\AccountProxyInterface $current_user: The current user.

string $property: The property against we need to check the access.

Return value

bool Return TRUE if current user is allowed to see the property else FALSE.

1 call to _social_profile_check_property_access()
social_profile_preprocess_profile in modules/social_features/social_profile/social_profile.module
Prepares variables for profile templates.

File

modules/social_features/social_profile/social_profile.module, line 415
The Social profile module.

Code

function _social_profile_check_property_access(Profile $profile, AccountProxyInterface $current_user, string $property) {

  // Flag to set.
  $flag = FALSE;
  switch ($property) {
    case 'email':

      // If the current user has this permission, return true straight away.
      if ($current_user
        ->hasPermission('social profile privacy view hidden fields') || $current_user
        ->hasPermission('view profile email')) {
        $flag = TRUE;
      }

      // Prepare some variables for checking on the email field.
      $global_show_email = \Drupal::config('social_profile.settings')
        ->get('social_profile_show_email');
      $profile_show_email = isset($profile->field_profile_show_email) ? $profile->field_profile_show_email->value : NULL;

      // If the current user doesn't have the above permission, perform
      // additional checks to see if the current user is still able to view
      // this email field.
      if ($global_show_email || !$global_show_email && !empty($profile_show_email)) {
        $flag = TRUE;
      }
      break;
    case 'language':

      // If the current user has this permission, return true straight away.
      if ($current_user
        ->hasPermission('view profile language')) {
        $flag = TRUE;
      }

      // Prepare some variables for checking on the language access.
      $global_show_lang = \Drupal::config('social_profile.settings')
        ->get('social_profile_show_language');
      $profile_show_lang = \Drupal::service('user.data')
        ->get('social_profile_privacy', $profile
        ->get('uid')->target_id, 'lang_info') ?? NULL;

      // If the current user doesn't have the above permission, perform
      // additional checks to see if the current user is still able to view
      // this preferred language.
      if ($global_show_lang || !$global_show_lang && !empty($profile_show_lang)) {
        $flag = TRUE;
      }
      break;
  }
  return $flag;
}