/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $bundle = $this->assigner->getBundle($this->bundle); $this->assigner->assignConfigPackages(); $this->package->setName($form_state->getValue('name')); $this->package->setMachineName($form_state->getValue('machine_name')); $this->package->setDescription($form_state->getValue('description')); $this->package->setVersion($form_state->getValue('version')); $this->package->setBundle($bundle->getMachineName()); // Save it first just to create it in case it's a new package. $this->featuresManager->setPackage($this->package); $this->package->setConfig($this->updatePackageConfig($form_state)); $this->package->setExcluded($this->updateExcluded()); $this->package->setRequired($this->updateRequired()); // Now save it with the selected config data. $this->featuresManager->setPackage($this->package); $method_id = NULL; $trigger = $form_state->getTriggeringElement(); $op = $form_state->getValue('op'); if (!empty($trigger) && empty($op)) { $method_id = $trigger['#name']; } // Set default redirect, but allow generators to change it later. $form_state->setRedirect('features.edit', array('featurename' => $this->package->getMachineName())); if (!empty($method_id)) { $packages = array($this->package->getMachineName()); $this->generator->generatePackages($method_id, $packages, $bundle); $this->generator->applyExportFormSubmit($method_id, $form, $form_state); } $this->assigner->setCurrent($bundle); }
/** * Initializes and returns a package or profile array. * * @param string $machine_name * Machine name of the package. * @param string $name * (optional) Human readable name of the package. * @param string $description * (optional) Description of the package. * @param string $type * (optional) Type of project. * @param \Drupal\features\FeaturesBundleInterface $bundle * (optional) Bundle to use to add profile directories to the scan. * @param \Drupal\Core\Extension\Extension $extension * (optional) An Extension object. * * @return \Drupal\features\Package * An array of package properties; see * FeaturesManagerInterface::getPackages(). */ protected function getPackageObject($machine_name, $name = NULL, $description = '', $type = 'module', FeaturesBundleInterface $bundle = NULL, Extension $extension = NULL) { if (!isset($bundle)) { $bundle = $this->getAssigner()->getBundle(); } $package = new Package($machine_name, ['name' => isset($name) ? $name : ucwords(str_replace(['_', '-'], ' ', $machine_name)), 'description' => $description, 'type' => $type, 'core' => Drupal::CORE_COMPATIBILITY, 'dependencies' => [], 'themes' => [], 'config' => [], 'status' => FeaturesManagerInterface::STATUS_DEFAULT, 'version' => '', 'state' => FeaturesManagerInterface::STATE_DEFAULT, 'directory' => $machine_name, 'files' => [], 'bundle' => $bundle->isDefault() ? '' : $bundle->getMachineName(), 'extension' => NULL, 'info' => [], 'configOrig' => []]); // If no extension was passed in, look for a match. if (!isset($extension)) { $module_list = $this->getFeaturesModules($bundle); $full_name = $bundle->getFullName($package->getMachineName()); if (isset($module_list[$full_name])) { $extension = $module_list[$full_name]; } } // If there is an extension, set extension-specific properties. if (isset($extension)) { $info = $this->getExtensionInfo($extension); $features_info = $this->getFeaturesInfo($extension); $package->setExtension($extension); $package->setInfo($info); $package->setFeaturesInfo($features_info); $package->setConfigOrig($this->listExtensionConfig($extension)); $package->setStatus($this->moduleHandler->moduleExists($extension->getName()) ? FeaturesManagerInterface::STATUS_INSTALLED : FeaturesManagerInterface::STATUS_UNINSTALLED); $package->setVersion(isset($info['version']) ? $info['version'] : ''); } return $package; }