You are here

public function RealisticDummyContentAttribute::fileSave in Realistic Dummy Content 8.2

Same name and namespace in other branches
  1. 7.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::fileSave()
  2. 3.x 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 317

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();
  $return = Framework::instance()
    ->fileSave($drupal_file);
  if (!is_object($return)) {
    throw new \Exception('Internal error, ' . __FUNCTION__ . ' expecting to return an object');
  }
  return $return;
}