/** * Registers a failed package or profile archive operation. * * @param array &$return * The return value, passed by reference. * @param \Drupal\features\Package $package * The package or profile. * @param \Exception $exception * The exception object. * @param string $message * Error message when there isn't an Exception object. */ protected function failure(array &$return, Package $package, \Exception $exception = NULL, $message = '') { $type = $package->getType() == 'module' ? $this->t('Package') : $this->t('Profile'); $return[] = ['success' => FALSE, 'display' => FALSE, 'message' => '@type @package not written to archive. Error: @error.', 'variables' => ['@type' => $type, '@package' => $package->getName(), '@error' => isset($exception) ? $exception->getMessage() : $message]]; }
/** * 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'); }