public function FeaturesGenerationArchive::generate in Features 8.4
Same name and namespace in other branches
- 8.3 src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationArchive::generate()
Performs package generation.
Parameters
array $packages: Array of package data.
\Drupal\features\FeaturesBundleInterface $bundle: The optional bundle used for the generation. Used to generate profiles.
Return value
array Array of results for profile and/or packages, each result including the following keys:
- 'success': boolean TRUE or FALSE for successful writing.
- 'display': boolean TRUE if the message should be displayed to the user, otherwise FALSE.
- 'message': a message about the result of the operation.
- 'variables': an array of substitutions to be used in the message.
Overrides FeaturesGenerationMethodInterface::generate
File
- src/
Plugin/ FeaturesGeneration/ FeaturesGenerationArchive.php, line 144
Class
- FeaturesGenerationArchive
- Class for generating a compressed archive of packages.
Namespace
Drupal\features\Plugin\FeaturesGenerationCode
public function generate(array $packages = [], FeaturesBundleInterface $bundle = NULL) {
// If no packages were specified, get all packages.
if (empty($packages)) {
$packages = $this->featuresManager
->getPackages();
}
// Determine the best name for the tar archive.
// Single package export, so name by package name.
if (count($packages) == 1) {
$filename = current($packages)
->getMachineName();
}
elseif (isset($bundle) && $bundle
->isProfile()) {
$filename = $bundle
->getProfileName();
}
elseif (isset($bundle) && !$bundle
->isDefault()) {
$filename = $bundle
->getMachineName();
}
else {
$filename = 'generated_features';
}
$return = [];
$this->archiveName = $filename . '.tar.gz';
$archive_name = $this->fileSystem
->getTempDirectory() . '/' . $this->archiveName;
if (file_exists($archive_name)) {
$this->fileSystem
->delete($archive_name);
}
$archiver = new ArchiveTar($archive_name);
// Add package files.
foreach ($packages as $package) {
if (count($packages) == 1) {
// Single module export, so don't generate entire modules dir structure.
$package
->setDirectory($package
->getMachineName());
}
$this
->generatePackage($return, $package, $archiver);
}
return $return;
}