You are here

public static function PhotosUpload::path in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 src/PhotosUpload.php \Drupal\photos\PhotosUpload::path()
  2. 6.0.x src/PhotosUpload.php \Drupal\photos\PhotosUpload::path()

Prepare photos custom directory structure.

4 calls to PhotosUpload::path()
PhotosUpload::moveImageFiles in src/PhotosUpload.php
Assist batch operation by moving or copying image files to album.
PhotosUpload::unzip in src/PhotosUpload.php
Unzip archive of image files.
PhotosUploadForm::submitForm in src/Form/PhotosUploadForm.php
Form submission handler.
photos_access_move_files in photos_access/photos_access.module
Move files from public to private and private to public as needed.

File

src/PhotosUpload.php, line 122

Class

PhotosUpload
Functions to help with uploading images to albums.

Namespace

Drupal\photos

Code

public static function path($type = 'default', $file = FALSE, $account = FALSE) {
  if (!$account) {
    $user = \Drupal::currentUser();
    $account = $user;
  }
  $path = [];
  if (\Drupal::config('photos.settings')
    ->get('photos_path')) {
    $mm = \Drupal::service('date.formatter')
      ->format(\Drupal::time()
      ->getRequestTime(), 'custom', "Y|m|d");
    $m = explode('|', $mm);
    $a = [
      '%uid' => $account
        ->id(),
      '%username' => $account
        ->getAccountName(),
      '%Y' => $m[0],
      '%m' => $m[1],
      '%d' => $m[2],
    ];
    $b = strtr(\Drupal::config('photos.settings')
      ->get('photos_path'), $a);
    $path = explode('/', $b);
  }
  else {
    $path[] = 'photos';
  }
  switch ($type) {
    case 'default':
      $scheme = \Drupal::config('system.file')
        ->get('default_scheme');
      break;
    case 'private':
      $scheme = 'private';
      break;
    case 'public':
      $scheme = 'public';
      break;
  }
  $dirs = [];
  $t = FALSE;
  foreach ($path as $folder) {
    $dirs[] = $folder;
    $t = $scheme . '://' . implode('/', $dirs);
    if (!\Drupal::service('file_system')
      ->prepareDirectory($t, FileSystemInterface::CREATE_DIRECTORY)) {
      return FALSE;
    }
  }
  return $t;
}