You are here

public function RealisticDummyContentAttribute::fileSave in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::fileSave()
  2. 7.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::fileSave()

Return a file object.

Parameters

object $file: The original file, a RealisticDummyContentFileGroup object.

Return value

object A file object.

Throws

\Exception.

1 call to RealisticDummyContentAttribute::fileSave()
RealisticDummyContentAttribute::imageSave in api/src/includes/RealisticDummyContentAttribute.php
Return an image file object if possible.

File

api/src/includes/RealisticDummyContentAttribute.php, line 323

Class

RealisticDummyContentAttribute
Represents either a field or a property for an entity.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public function fileSave($file) {
  $drupal_file = $file
    ->getFile();
  if (!$drupal_file) {
    throw new RealisticDummyContentException('Please check if the file exists before attempting to save it');
  }
  $random = $file
    ->getRadical();
  $drupal_file = $this
    ->env()
    ->fileSaveData($file
    ->value(), 'public://dummyfile' . $random . '.' . $file
    ->getRadicalExtension());
  $drupal_file->uid = $this
    ->getUid();
  $drupal_file
    ->save();
  return $drupal_file;
}