protected function FeaturesGenerationWrite::generateFile in Features 8.3
Same name and namespace in other branches
- 8.4 src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite::generateFile()
Writes a file to the file system, creating its directory as needed.
Parameters
string $directory: The extension's directory.
array $file: Array with the following keys:
- 'filename': the name of the file.
- 'subdirectory': any subdirectory of the file within the extension directory.
- 'string': the contents of the file.
Throws
Exception
1 call to FeaturesGenerationWrite::generateFile()
- FeaturesGenerationWrite::generatePackage in src/
Plugin/ FeaturesGeneration/ FeaturesGenerationWrite.php - Writes a package or profile's files to the file system.
File
- src/
Plugin/ FeaturesGeneration/ FeaturesGenerationWrite.php, line 225
Class
- FeaturesGenerationWrite
- Class for writing packages to the local file system.
Namespace
Drupal\features\Plugin\FeaturesGenerationCode
protected function generateFile($directory, array $file) {
if (!empty($file['subdirectory'])) {
$directory .= '/' . $file['subdirectory'];
}
$directory = $this->root . '/' . $directory;
if (!is_dir($directory)) {
if ($this->fileSystem
->mkdir($directory, NULL, TRUE) === FALSE) {
throw new \Exception($this
->t('Failed to create directory @directory.', [
'@directory' => $directory,
]));
}
}
if (file_put_contents($directory . '/' . $file['filename'], $file['string']) === FALSE) {
throw new \Exception($this
->t('Failed to write file @filename.', [
'@filename' => $file['filename'],
]));
}
}