You are here

public function FeaturesAssigner::createBundlesFromPackages in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/FeaturesAssigner.php \Drupal\features\FeaturesAssigner::createBundlesFromPackages()

Creates bundles by parsing information from installed packages.

Overrides FeaturesAssignerInterface::createBundlesFromPackages

1 call to FeaturesAssigner::createBundlesFromPackages()
FeaturesAssigner::__construct in src/FeaturesAssigner.php
Constructs a new FeaturesAssigner object.

File

src/FeaturesAssigner.php, line 339

Class

FeaturesAssigner
Class responsible for performing package assignment.

Namespace

Drupal\features

Code

public function createBundlesFromPackages() {
  $existing_bundles = $this
    ->getBundleList();
  $new_bundles = [];

  // Only parse from installed features.
  $modules = $this->featuresManager
    ->getFeaturesModules(NULL, TRUE);
  foreach ($modules as $module) {
    $info = $this->featuresManager
      ->getExtensionInfo($module);

    // @todo This entire function could be simplified a lot using packages.
    $features_info = $this->featuresManager
      ->getFeaturesInfo($module);

    // Create a new bundle if:
    // - the feature specifies a bundle and
    // - that bundle doesn't yet exist locally.
    // Allow profiles to override previous values.
    if (!empty($features_info['bundle']) && !isset($existing_bundles[$features_info['bundle']]) && (!in_array($features_info['bundle'], $new_bundles) || $info['type'] == 'profile')) {
      if ($info['type'] == 'profile') {
        $new_bundle = [
          'name' => $info['name'],
          'description' => $info['description'],
          'is_profile' => TRUE,
          'profile_name' => $module
            ->getName(),
        ];
      }
      else {
        $new_bundle = [
          'name' => isset($info['package']) ? $info['package'] : ucwords(str_replace('_', ' ', $features_info['bundle'])),
          'description' => NULL,
          'is_profile' => FALSE,
          'profile_name' => NULL,
        ];
      }
      $new_bundle['machine_name'] = $features_info['bundle'];
      $new_bundles[$new_bundle['machine_name']] = $new_bundle;
    }
  }
  foreach ($new_bundles as $new_bundle) {
    $this
      ->createBundleFromDefault($new_bundle['machine_name'], $new_bundle['name'], $new_bundle['description'], $new_bundle['is_profile']);
  }
}