protected function FeaturesManager::addInfoFile in Features 8.3
Same name and namespace in other branches
- 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::addInfoFile()
Generates and adds .info.yml files to a package.
Parameters
\Drupal\features\Package $package: The package.
1 call to FeaturesManager::addInfoFile()
- FeaturesManager::addPackageFiles in src/
FeaturesManager.php - Generates and adds files to a given package or profile.
File
- src/
FeaturesManager.php, line 951
Class
- FeaturesManager
- The FeaturesManager provides helper functions for building packages.
Namespace
Drupal\featuresCode
protected function addInfoFile(Package $package) {
$info = [
'name' => $package
->getName(),
'description' => $package
->getDescription(),
'type' => $package
->getType(),
'core_version_requirement' => $package
->getCoreVersionRequirement(),
'dependencies' => $package
->getDependencies(),
'themes' => $package
->getThemes(),
'version' => $package
->getVersion(),
];
$features_info = [];
// Assign to a "package" named for the profile.
if ($package
->getBundle()) {
$bundle = $this
->getAssigner()
->getBundle($package
->getBundle());
}
// Save the current bundle in the info file so the package
// can be reloaded later by the AssignmentPackages plugin.
if (isset($bundle) && !$bundle
->isDefault()) {
$info['package'] = $bundle
->getName();
$features_info['bundle'] = $bundle
->getMachineName();
}
else {
unset($features_info['bundle']);
}
if ($package
->getConfig()) {
foreach ([
'excluded',
'required',
] as $constraint) {
if (!empty($package
->{'get' . $constraint}())) {
$features_info[$constraint] = $package
->{'get' . $constraint}();
}
else {
unset($features_info[$constraint]);
}
}
if (empty($features_info)) {
$features_info = TRUE;
}
}
// The name and description need to be cast as strings from the
// TranslatableMarkup objects returned by t() to avoid raising an
// InvalidDataTypeException on Yaml serialization.
foreach ([
'name',
'description',
] as $key) {
$info[$key] = (string) $info[$key];
}
// Add profile-specific info data.
if ($info['type'] == 'profile') {
// Set the distribution name.
$info['distribution'] = [
'name' => $info['name'],
];
}
$package
->appendFile([
'filename' => $package
->getMachineName() . '.info.yml',
'subdirectory' => NULL,
// Filter to remove any empty keys, e.g., an empty themes array.
'string' => Yaml::encode(array_filter($info)),
], 'info');
$package
->appendFile([
'filename' => $package
->getMachineName() . '.features.yml',
'subdirectory' => NULL,
'string' => Yaml::encode($features_info),
], 'features');
}