/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $bundle_name = NULL) { $this->currentBundle = $this->assigner->loadBundle($bundle_name); $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); $this->setTypeSelect($form, $settings['types'], $this->t('exclude')); $module_settings = $settings['module']; $curated_settings = $settings['curated']; $form['curated'] = array( '#type' => 'checkbox', '#title' => t('Exclude designated site-specific configuration'), '#default_value' => $curated_settings, '#description' => $this->t('Select this option to exclude from packaging items on a curated list of site-specific configuration.'), ); $form['module'] = array( '#type' => 'container', '#tree' => TRUE, ); $form['module']['enabled'] = array( '#type' => 'checkbox', '#title' => t('Exclude module-provided entity configuration'), '#default_value' => $module_settings['enabled'], '#description' => $this->t('Select this option to exclude from packaging any configuration that is provided by already enabled modules. Note that <a href="!url">simple configuration</a> will not be excluded as it is always module-provided.', array('!url' => 'http://www.drupal.org/node/1809490')), '#attributes' => array( 'data-module-enabled' => 'status', ), ); $show_if_module_enabled_checked = array( 'visible' => array( ':input[data-module-enabled="status"]' => array('checked' => TRUE), ), ); $info = system_get_info('module', drupal_get_profile()); $form['module']['profile'] = array( '#type' => 'checkbox', '#title' => t("Don't exclude install profile's configuration"), '#default_value' => $module_settings['profile'], '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by this site's install profile, %profile.", array('%profile' => $info['name'])), '#states' => $show_if_module_enabled_checked, ); $machine_name = $this->currentBundle->getMachineName(); $machine_name = !empty($machine_name) ? $machine_name : t('none'); $form['module']['namespace'] = array( '#type' => 'checkbox', '#title' => t("Don't exclude configuration by namespace"), '#default_value' => $module_settings['namespace'], '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by modules with the package namespace (currently %namespace).", array('%namespace' => $machine_name)), '#states' => $show_if_module_enabled_checked, ); $this->setActions($form); return $form; }
/** * {@inheritdoc} */ public function renameBundle($old_machine, $new_machine) { $is_current = (isset($this->currentBundle) && ($old_machine == $this->currentBundle->getMachineName())); $bundle = $this->getBundle($old_machine); if ($bundle->getMachineName() != '') { // Remove old bundle from the list if it's not the Default bundle. unset($this->bundles[$old_machine]); } $bundle->setMachineName($new_machine); $this->setBundle($bundle); // Put the bundle into the list with the correct name. $this->bundles[$bundle->getMachineName()] = $bundle; if ($is_current) { $this->setCurrent($bundle); } return $bundle; }
/** * {@inheritdoc} */ public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL) { $filename = isset($bundle) ? $bundle->getMachineName() : 'features_archive'; // If no packages were specified, get all packages. if (empty($packages)) { $packages = $this->featuresManager->getPackages(); } elseif (count($packages) == 1) { // Single package export, so name tar archive by package name. $filename = current($packages)['machine_name']; } $return = []; $filename = (isset($bundle) && $bundle->isProfile()) ? $bundle->getProfileName() : $filename; $this->archiveName = $filename . '.tar.gz'; $archive_name = file_directory_temp() . '/' . $this->archiveName; if (file_exists($archive_name)) { file_unmanaged_delete($archive_name); } $archiver = new ArchiveTar($archive_name); // Add the Profile. if (isset($bundle) && $bundle->isProfile()) { $profile_package = $this->featuresManager->getPackage($bundle->getProfileName()); if (!empty($profile_package)) { $this->generatePackage($return, $profile_package, $archiver); } } // Add package files. foreach ($packages as $package) { if (count($packages) == 1) { // Single module export, so don't generate entire modules dir structure. $package['directory'] = $package['machine_name']; } $this->generatePackage($return, $package, $archiver); } return $return; }
/** * {@inheritdoc} */ public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL) { // If no packages were specified, get all packages. if (empty($packages)) { $packages = $this->featuresManager->getPackages(); } // Determine the best name for the tar archive. // Single package export, so name by package name. if (count($packages) == 1) { $filename = current($packages)->getMachineName(); } elseif (isset($bundle) && $bundle->isProfile()) { $filename = $bundle->getProfileName(); } elseif (isset($bundle) && !$bundle->isDefault()) { $filename = $bundle->getMachineName(); } else { $filename = 'generated_features'; } $return = []; $this->archiveName = $filename . '.tar.gz'; $archive_name = file_directory_temp() . '/' . $this->archiveName; if (file_exists($archive_name)) { file_unmanaged_delete($archive_name); } $archiver = new ArchiveTar($archive_name); // Add package files. foreach ($packages as $package) { if (count($packages) == 1) { // Single module export, so don't generate entire modules dir structure. $package->setDirectory($package->getMachineName()); } $this->generatePackage($return, $package, $archiver); } return $return; }
/** * Adds the optional bundle prefix to package machine names. * * @param string[] &$package_names * Array of package names, passed by reference. * @param \Drupal\features\FeaturesBundleInterface $bundle * The optional bundle used for the generation. Used to generate profiles. */ protected function setPackageBundleNames(array &$package_names, FeaturesBundleInterface $bundle = NULL) { if ($bundle && !$bundle->isDefault()) { $new_package_names = []; // Assign the selected bundle to the exports. $packages = $this->featuresManager->getPackages(); foreach ($package_names as $package_name) { // Rename package to use bundle prefix. $package = $packages[$package_name]; // The install profile doesn't need renaming. if ($package['type'] != 'profile') { unset($packages[$package_name]); $package['machine_name'] = $bundle->getFullName($package['machine_name']); $packages[$package['machine_name']] = $package; } // Set the bundle machine name. $packages[$package['machine_name']]['bundle'] = $bundle->getMachineName(); $new_package_names[] = $package['machine_name']; } $this->featuresManager->setPackages($packages); $package_names = $new_package_names; } }
/** * {@inheritdoc} */ public function setCurrent(FeaturesBundleInterface $bundle) { $this->currentBundle = $bundle; $session = \Drupal::request()->getSession(); if (isset($session)) { $session->set('features_current_bundle', $bundle->getMachineName()); } return $bundle; }
/** * {@inheritdoc} */ public function setPackageBundleNames(FeaturesBundleInterface $bundle, array &$package_names = []) { $this->packagesPrefixed = TRUE; if (!$bundle->isDefault()) { $new_package_names = []; // Assign the selected bundle to the exports. $packages = $this->getPackages(); if (empty($package_names)) { $package_names = array_keys($packages); } foreach ($package_names as $package_name) { // Rename package to use bundle prefix. $package = $packages[$package_name]; // The install profile doesn't need renaming. if ($package->getType() != 'profile') { unset($packages[$package_name]); $package->setMachineName($bundle->getFullName($package->getMachineName())); $packages[$package->getMachineName()] = $package; } // Set the bundle machine name. $packages[$package->getMachineName()]->setBundle($bundle->getMachineName()); $new_package_names[] = $package->getMachineName(); } $this->setPackages($packages); $package_names = $new_package_names; } }
/** * Redirects back to the Bundle config form. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ protected function setRedirect(FormStateInterface $form_state) { $form_state->setRedirect('features.assignment', array('bundle_name' => $this->currentBundle->getMachineName())); }