FeaturesGenerationMethodBase.php in Features 8.4
File
src/FeaturesGenerationMethodBase.php
View source
<?php
namespace Drupal\features;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
abstract class FeaturesGenerationMethodBase implements FeaturesGenerationMethodInterface {
use StringTranslationTrait;
protected $featuresManager;
protected $assigner;
public function setFeaturesManager(FeaturesManagerInterface $features_manager) {
$this->featuresManager = $features_manager;
}
public function setAssigner(FeaturesAssignerInterface $assigner) {
$this->assigner = $assigner;
}
public function exportFormSubmit(array &$form, FormStateInterface $form_state) {
}
protected function mergeInfoFile($package_info, $info_file_uri) {
$package_info = Yaml::decode($package_info);
$existing_info = Yaml::decode(file_get_contents($info_file_uri));
if (isset($existing_info['core'])) {
unset($existing_info['core']);
}
return Yaml::encode($this->featuresManager
->mergeInfoArray($existing_info, $package_info));
}
public function prepare(array &$packages = [], FeaturesBundleInterface $bundle = NULL) {
if (empty($packages)) {
$packages = $this->featuresManager
->getPackages();
}
$existing_packages = $this->featuresManager
->listPackageDirectories(array_keys($packages), $bundle);
foreach ($packages as &$package) {
list($full_name, $path) = $this->featuresManager
->getExportInfo($package, $bundle);
if (empty($package
->getDirectory())) {
$package
->setDirectory($path);
}
if (!isset($bundle) || !$bundle
->isProfilePackage($package
->getMachineName())) {
$current_path = $package
->getDirectory();
if (strpos($current_path, $full_name) < strlen($current_path) - strlen($full_name)) {
$package
->setDirectory($package
->getDirectory() . '/' . $full_name);
}
}
$this
->preparePackage($package, $existing_packages, $bundle);
}
unset($package);
}
protected abstract function preparePackage(Package $package, array $existing_packages, FeaturesBundleInterface $bundle = NULL);
}