FileGenerator.php in YAML Content 8.2
File
modules/sample_data/src/Plugin/SampleData/FileGenerator.php
View source
<?php
namespace Drupal\sample_data\Plugin\SampleData;
class FileGenerator {
public function execute() {
$sample = $this
->getFile($this->configuration['path'], $this->configuration['src']);
return $sample;
}
public function getFile($file_path, $file_src) {
$file = file_get_contents($file_src);
$destination = \Drupal::service('file_system')
->dirname("public://{$file_path}");
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
return file_save_data($file, "public://{$file_path}", FILE_EXISTS_REPLACE);
}
}
Classes
Name |
Description |
FileGenerator |
Sample data generator to provide basic placeholder images. |