You are here

public function AssetFileStorage::createFile in Asset Injector 8

Same name and namespace in other branches
  1. 8.2 src/AssetFileStorage.php \Drupal\asset_injector\AssetFileStorage::createFile()

Create file and return internal uri.

Return value

string Internal file URI using public:// stream wrapper.

File

src/AssetFileStorage.php, line 50

Class

AssetFileStorage
Class AssetFileStorage.

Namespace

Drupal\asset_injector

Code

public function createFile() {
  $internal_uri = self::internalFileUri();
  if (!is_file($internal_uri)) {
    $directory = dirname($internal_uri);
    file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    file_unmanaged_save_data($this->asset
      ->getCode(), $internal_uri, FILE_EXISTS_REPLACE);
  }
  return $internal_uri;
}