You are here

public static function Imce::userProfile in IMCE 8

Same name and namespace in other branches
  1. 8.2 src/Imce.php \Drupal\imce\Imce::userProfile()

Returns imce configuration profile for a user.

2 calls to Imce::userProfile()
Imce::access in src/Imce.php
Checks if a user has an imce profile assigned for a file scheme.
Imce::userConf in src/Imce.php
Returns processed profile configuration for a user.

File

src/Imce.php, line 42

Class

Imce
Imce container class for helper methods.

Namespace

Drupal\imce

Code

public static function userProfile(AccountProxyInterface $user = NULL, $scheme = NULL) {
  $profiles =& drupal_static(__METHOD__, []);
  $user = $user ?: \Drupal::currentUser();
  $scheme = isset($scheme) ? $scheme : \Drupal::config('system.file')
    ->get('default_scheme');
  $profile =& $profiles[$user
    ->id()][$scheme];
  if (isset($profile)) {
    return $profile;
  }
  $profile = FALSE;
  if (\Drupal::service('stream_wrapper_manager')
    ->getViaScheme($scheme)) {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('imce_profile');
    if ($user
      ->id() == 1 && ($profile = $storage
      ->load('admin'))) {
      return $profile;
    }
    $imce_settings = \Drupal::config('imce.settings');
    $roles_profiles = $imce_settings
      ->get('roles_profiles');
    $user_roles = array_flip($user
      ->getRoles());

    // Order roles from more permissive to less permissive.
    $roles = array_reverse(user_roles());
    foreach ($roles as $rid => $role) {
      if (isset($user_roles[$rid]) && !empty($roles_profiles[$rid][$scheme])) {
        if ($profile = $storage
          ->load($roles_profiles[$rid][$scheme])) {
          return $profile;
        }
      }
    }
  }
  return $profile;
}