You are here

public function FeaturesAssigner::createBundleFromDefault in Features 8.3

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

Creates a new bundle by duplicating the default bundle and customizing.

Parameters

string $name: (optional) Human readable name of the bundle.

string $machine_name: Machine name.

string $description: (optional) Description of the bundle.

bool $is_profile: (optional) TRUE if a profile is used with this bundle.

string $profile_name: (optional) The machine name of the profile.

Return value

\Drupal\features\FeaturesBundleInterface A features bundle object.

Overrides FeaturesAssignerInterface::createBundleFromDefault

1 call to FeaturesAssigner::createBundleFromDefault()
FeaturesAssigner::createBundlesFromPackages in src/FeaturesAssigner.php
Creates bundles by parsing information from installed packages.

File

src/FeaturesAssigner.php, line 302

Class

FeaturesAssigner
Class responsible for performing package assignment.

Namespace

Drupal\features

Code

public function createBundleFromDefault($machine_name, $name = NULL, $description = NULL, $is_profile = FALSE, $profile_name = NULL) {

  // Duplicate the default bundle to get its default configuration.
  $default = $this
    ->getBundle(FeaturesBundleInterface::DEFAULT_BUNDLE);
  if (!$default) {

    // If we don't have the default installed, generate it from the install
    // config file.
    $ext_storage = new ExtensionInstallStorage($this->configStorage, ExtensionInstallStorage::CONFIG_INSTALL_DIRECTORY, ExtensionInstallStorage::DEFAULT_COLLECTION, TRUE, $this->installProfile);
    $record = $ext_storage
      ->read('features.bundle.default');
    $bundle_storage = $this->entityTypeManager
      ->getStorage('features_bundle');
    $default = $bundle_storage
      ->createFromStorageRecord($record);
  }

  /** @var \Drupal\features\Entity\FeaturesBundle $bundle */
  $bundle = $default
    ->createDuplicate();
  $bundle
    ->setMachineName($machine_name);
  $name = !empty($name) ? $name : $machine_name;
  $bundle
    ->setName($name);
  if (isset($description)) {
    $bundle
      ->setDescription($description);
  }
  else {
    $bundle
      ->setDescription(t('Auto-generated bundle from package @name', [
      '@name' => $name,
    ]));
  }
  $bundle
    ->setIsProfile($is_profile);
  if (isset($profile_name)) {
    $bundle
      ->setProfileName($profile_name);
  }
  $bundle
    ->save();
  $this
    ->setBundle($bundle);
  return $bundle;
}