Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig('features');
     $this->installConfig('system');
     $this->featuresManager = \Drupal::service('features.manager');
     $this->assigner = \Drupal::service('features_assigner');
     $this->bundle = $this->assigner->getBundle();
     // Turn off all assignment plugins.
     $this->bundle->setEnabledAssignments([]);
     // Start with an empty configuration collection.
     $this->featuresManager->setConfigCollection([]);
 }
  /**
   * Generates and adds .info.yml files to a package.
   *
   * @param array $package
   *   The package.
   */
  protected function addInfoFile(array &$package) {
    // Filter to standard keys of the profiles that we will use in info files.
    $info_keys = [
      'name',
      'description',
      'type',
      'core',
      'dependencies',
      'themes',
      'version'
    ];
    $info = array_intersect_key($package, array_fill_keys($info_keys, NULL));

    // Assign to a "package" named for the profile.
    if (isset($package['bundle'])) {
      $bundle = $this->assigner->getBundle($package['bundle']);
    }
    if (isset($bundle) && !$bundle->isDefault()) {
      $info['package'] = $bundle->getName();
    }

    if (!empty($package['config'])) {
      // Save the current bundle in the info file so the package
      // can be reloaded later by the AssignmentPackages plugin.
      if (isset($bundle) && !$bundle->isDefault()) {
        $info['features']['bundle'] = $bundle->getMachineName();
      }
      else {
        unset($info['features']['bundle']);
      }
      if (!empty($package['excluded'])) {
        $info['features']['excluded'] = $package['excluded'];
      }
      else {
        unset($info['features']['excluded']);
      }
      if (empty($info['features'])) {
        $info['features'] = TRUE;
      }
    }

    // Add profile-specific info data.
    if ($info['type'] == 'profile') {
      // Set the distribution name.
      $info['distribution'] = [
        'name' => $info['name']
      ];
    }

    $package['files']['info'] = [
      'filename' => $package['machine_name'] . '.info.yml',
      'subdirectory' => NULL,
      // Filter to remove any empty keys, e.g., an empty themes array.
      'string' => Yaml::encode(array_filter($info))
    ];
  }