You are here

protected function FeaturesGenerationWrite::preparePackage in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite::preparePackage()

Reads and merges in existing files for a given package or profile.

Parameters

\Drupal\features\Package $package: The package.

array $existing_packages: An array of existing packages.

\Drupal\features\FeaturesBundleInterface $bundle: The bundle the package belongs to.

Overrides FeaturesGenerationMethodBase::preparePackage

File

src/Plugin/FeaturesGeneration/FeaturesGenerationWrite.php, line 76

Class

FeaturesGenerationWrite
Class for writing packages to the local file system.

Namespace

Drupal\features\Plugin\FeaturesGeneration

Code

protected function preparePackage(Package $package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) {

  // If this package is already present, prepare files.
  if (isset($existing_packages[$package
    ->getMachineName()])) {
    $existing_directory = $existing_packages[$package
      ->getMachineName()];
    $package
      ->setDirectory($existing_directory);
  }
  else {
    $existing_directory = $package
      ->getDirectory();
  }

  // Merge in the info file.
  $info_file_uri = $this->root . '/' . $existing_directory . '/' . $package
    ->getMachineName() . '.info.yml';
  if (file_exists($info_file_uri)) {
    $files = $package
      ->getFiles();
    $files['info']['string'] = $this
      ->mergeInfoFile($package
      ->getFiles()['info']['string'], $info_file_uri);
    $package
      ->setFiles($files);

    // Remove the config directories, as they will be replaced.
    foreach (array_keys($this->featuresManager
      ->getExtensionStorages()
      ->getExtensionStorages()) as $directory) {
      $config_directory = $this->root . '/' . $existing_directory . '/' . $directory;
      if (is_dir($config_directory)) {
        $this->fileSystem
          ->deleteRecursive($config_directory);
      }
    }
  }
}