You are here

protected function FeaturesGenerator::generate in Features 8.3

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

Generates a file representation of configuration packages and, optionally, an install profile.

Parameters

string $method_id: The ID of the generation method to use.

\Drupal\features\FeaturesBundleInterface $bundle: The bundle used for the generation.

string[] $package_names: Names of packages to be generated. If none are specified, all available packages will be added.

Return value

array Array of results for profile and/or packages, each result including the following keys:

  • 'success': boolean TRUE or FALSE for successful writing.
  • 'display': boolean TRUE if the message should be displayed to the user, otherwise FALSE.
  • 'message': a message about the result of the operation.
  • 'variables': an array of substitutions to be used in the message.
1 call to FeaturesGenerator::generate()
FeaturesGenerator::generatePackages in src/FeaturesGenerator.php
Generates file representations of configuration packages.

File

src/FeaturesGenerator.php, line 171

Class

FeaturesGenerator
Class responsible for performing package generation.

Namespace

Drupal\features

Code

protected function generate($method_id, FeaturesBundleInterface $bundle, array $package_names = []) {
  $packages = $this->featuresManager
    ->getPackages();

  // Filter out the packages that weren't requested.
  if (!empty($package_names)) {
    $packages = array_intersect_key($packages, array_fill_keys($package_names, NULL));
  }
  $this->featuresManager
    ->assignInterPackageDependencies($bundle, $packages);

  // Prepare the files.
  $this->featuresManager
    ->prepareFiles($packages);
  $return = $this
    ->applyGenerationMethod($method_id, $packages, $bundle);
  foreach ($return as $message) {
    if ($message['display']) {
      $type = $message['success'] ? 'status' : 'error';
      $this->messenger
        ->addMessage($this
        ->t($message['message'], $message['variables']), $type);
    }
    $type = $message['success'] ? 'notice' : 'error';
    $this->logger
      ->{$type}($message['message'], $message['variables']);
  }
  return $return;
}