You are here

function Attribute::FileSave in Realistic Dummy Content 8

Return a file object.

Parameters

$file: The original file, a FileGroup object.

Return value

A file object.

Throws

\Exception.

1 call to Attribute::FileSave()
Attribute::ImageSave in api/src/attributes/Attribute.php
Return an image file object if possible.

File

api/src/attributes/Attribute.php, line 333
Define autoload class.

Class

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

Namespace

Drupal\realistic_dummy_content_api\attributes

Code

function FileSave($file) {
  $drupal_file = $file
    ->GetFile();
  if (!$drupal_file) {
    throw new Exception('Please check if the file exists before attempting to save it');
  }
  $uri = $drupal_file->uri;

  //$random = md5($uri) . rand(1000000000, 9999999999);

  // DO NOT RENAME FOR TESTING
  $random = $file
    ->GetRadical();
  $drupal_file = $this
    ->env()
    ->file_save_data($file
    ->Value(), 'public://dummyfile' . $random . '.' . $file
    ->GetRadicalExtension());
  $drupal_file->uid = $this
    ->GetUid();
  $return = $drupal_file
    ->save();
  return $return;
}