/** * {@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->setDirectory($form_state->getValue('directory')); $this->package->setBundle($bundle->getMachineName()); // Save it first just to create it in case it's a new package. $this->featuresManager->setPackage($this->package); $config = $this->updatePackageConfig($form_state); $this->featuresManager->assignConfigPackage($this->package->getMachineName(), $config, TRUE); $this->package->setExcluded($this->updateExcluded()); if ($form_state->getValue('require_all')) { $this->package->setRequired(TRUE); } else { $required = $this->updateRequired(); $this->package->setRequired($required); } // 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 ($method_id == 'import_missing') { $this->importMissing(); } elseif (!empty($method_id)) { $packages = array($this->package->getMachineName()); $this->generator->generatePackages($method_id, $bundle, $packages); $this->generator->applyExportFormSubmit($method_id, $form, $form_state); } $this->assigner->setCurrent($bundle); }
/** * Reads and merges in existing files for a given package or profile. * * @param \Drupal\features\Package &$package * The package. * @param array $existing_packages * An array of existing packages. * @param \Drupal\features\FeaturesBundleInterface $bundle * The bundle the package belongs to. */ protected function preparePackage(Package $package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) { // If this package is already present, prepare files. if (isset($existing_packages[$package->getMachineName()])) { $existing_directory = $existing_packages[$package->getMachineName()]; $package->setDirectory($existing_directory); // Merge in the info file. $info_file_uri = $this->root . '/' . $existing_directory . '/' . $package->getMachineName() . '.info.yml'; if (file_exists($info_file_uri)) { $files = $package->getFiles(); $files['info']['string'] = $this->mergeInfoFile($package->getFiles()['info']['string'], $info_file_uri); $package->setFiles($files); } // Remove the config directories, as they will be replaced. foreach (array_keys($this->featuresManager->getExtensionStorages()->getExtensionStorages()) as $directory) { $config_directory = $this->root . '/' . $existing_directory . '/' . $directory; if (is_dir($config_directory)) { file_unmanaged_delete_recursive($config_directory); } } } }
/** * Generates and adds files to a given package or profile. */ protected function addPackageFiles(Package $package) { $config_collection = $this->getConfigCollection(); // Ensure the directory reflects the current full machine name. $package->setDirectory($package->getMachineName()); // Only add files if there is at least one piece of configuration // present. if ($package->getConfig()) { // Add .info.yml files. $this->addInfoFile($package); // Add configuration files. foreach ($package->getConfig() as $name) { $config = $config_collection[$name]; // The UUID is site-specfic, so don't export it. if ($entity_type_id = $this->configManager->getEntityTypeIdByName($name)) { $data = $config->getData(); unset($data['uuid']); $config->setData($data); } // User roles include all permissions currently assigned to them. To // avoid extraneous additions, reset permissions. if ($config->getType() == 'user_role') { $data = $config->getData(); $data['permissions'] = []; $config->setData($data); } $package->appendFile(['filename' => $config->getName() . '.yml', 'subdirectory' => $config->getSubdirectory(), 'string' => Yaml::encode($config->getData())], $name); } } }