You are here

public static function PhotosAlbum::userAlbumCount in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::userAlbumCount()
  2. 8.4 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::userAlbumCount()

Tracks number of albums created and number of albums allowed.

3 calls to PhotosAlbum::userAlbumCount()
photos_form_node_form_alter in ./photos.module
Implements hook_form_BASE_FORM_ID_alter().
photos_node_form_validate in ./photos.module
Form validator to check user album limit.
photos_user_view in ./photos.module
Implements hook_ENTITY_TYPE_view() for user entities.

File

src/PhotosAlbum.php, line 693

Class

PhotosAlbum
Create an album object.

Namespace

Drupal\photos

Code

public static function userAlbumCount() {
  $user = \Drupal::currentUser();
  $user_roles = $user
    ->getRoles();
  $t['create'] = PhotosAlbum::getCount('user_album', $user
    ->id());

  // @todo upgrade path? Check D7 role id and convert pnum variables as needed.
  $role_limit = 0;
  $t['total'] = 20;

  // Check highest role limit.
  foreach ($user_roles as $role) {
    if (\Drupal::config('photos.settings')
      ->get('photos_pnum_' . $role) && \Drupal::config('photos.settings')
      ->get('photos_pnum_' . $role) > $role_limit) {
      $role_limit = \Drupal::config('photos.settings')
        ->get('photos_pnum_' . $role);
    }
  }
  if ($role_limit > 0) {
    $t['total'] = $role_limit;
  }
  $t['remain'] = $t['total'] - $t['create'];
  if ($user
    ->id() != 1 && $t['remain'] <= 0) {
    $t['rest'] = 1;
  }
  return $t;
}