示例#1
0
 /**
  * Generates and adds .info.yml files to a package.
  *
  * @param \Drupal\features\Package $package
  *   The package.
  */
 protected function addInfoFile(Package $package)
 {
     $info = ['name' => $package->getName(), 'description' => $package->getDescription(), 'type' => $package->getType(), 'core' => $package->getCore(), 'dependencies' => $package->getDependencies(), 'themes' => $package->getThemes(), 'version' => $package->getVersion()];
     $features_info = [];
     // Assign to a "package" named for the profile.
     if ($package->getBundle()) {
         $bundle = $this->getAssigner()->getBundle($package->getBundle());
     }
     // 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['package'] = $bundle->getName();
         $features_info['bundle'] = $bundle->getMachineName();
     } else {
         unset($features_info['bundle']);
     }
     if ($package->getConfig()) {
         foreach (array('excluded', 'required') as $constraint) {
             if (!empty($package->{'get' . $constraint}())) {
                 $features_info[$constraint] = $package->{'get' . $constraint}();
             } else {
                 unset($features_info[$constraint]);
             }
         }
         if (empty($features_info)) {
             $features_info = TRUE;
         }
     }
     // The name and description need to be cast as strings from the
     // TranslatableMarkup objects returned by t() to avoid raising an
     // InvalidDataTypeException on Yaml serialization.
     foreach (array('name', 'description') as $key) {
         $info[$key] = (string) $info[$key];
     }
     // Add profile-specific info data.
     if ($info['type'] == 'profile') {
         // Set the distribution name.
         $info['distribution'] = ['name' => $info['name']];
     }
     $package->appendFile(['filename' => $package->getMachineName() . '.info.yml', 'subdirectory' => NULL, 'string' => Yaml::encode(array_filter($info))], 'info');
     $package->appendFile(['filename' => $package->getMachineName() . '.features.yml', 'subdirectory' => NULL, 'string' => Yaml::encode($features_info)], 'features');
 }