You are here

public static function PhotosUpload::saveFile in Album Photos 8.4

Write files.

3 calls to PhotosUpload::saveFile()
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.

File

src/PhotosUpload.php, line 40

Class

PhotosUpload
Functions to help with uploading images to albums.

Namespace

Drupal\photos

Code

public static function saveFile($file, $val = []) {
  $errors = [];
  foreach ($val as $function => $args) {
    array_unshift($args, $file);
    $errors = array_merge($errors, call_user_func_array($function, $args));
  }
  if (!empty($errors)) {
    $message = t('The selected file %name could not be uploaded.', [
      '%name' => $file->filename,
    ]);
    if (count($errors) > 1) {
      $message .= '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>';
    }
    else {
      $message .= ' ' . array_pop($errors);
    }
    \Drupal::messenger()
      ->addMessage($message);
    return 0;
  }
  $file
    ->save();
  return $file
    ->id();
}