/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $featurename = '') { $session = $this->getRequest()->getSession(); $trigger = $form_state->getTriggeringElement(); if ($trigger['#name'] == 'package') { $this->oldBundle = $this->bundle; $bundle_name = $form_state->getValue('package'); $bundle = $this->assigner->getBundle($bundle_name); } elseif ($trigger['#name'] == 'conflicts') { if (isset($session)) { $session->set('features_allow_conflicts', $form_state->getValue('conflicts')); } $bundle = $this->assigner->loadBundle(); } else { $bundle = $this->assigner->loadBundle(); } $this->bundle = $bundle->getMachineName(); $this->allowConflicts = FALSE; if (isset($session)) { $this->allowConflicts = $session->get('features_allow_conflicts', FALSE); } // Pass the $force argument as TRUE because we want to include any excluded // configuration items. These should show up as automatically assigned, but // not selected, thus allowing the admin to reselect if desired. // @see FeaturesManagerInterface::assignConfigPackage() $this->assigner->assignConfigPackages(TRUE); $packages = $this->featuresManager->getPackages(); if (empty($packages[$featurename])) { $featurename = str_replace(array('-', ' '), '_', $featurename); $this->package = $this->featuresManager->initPackage($featurename, NULL, '', 'module', $bundle); } else { $this->package = $packages[$featurename]; } $form = array('#show_operations' => FALSE, '#prefix' => '<div id="features-edit-wrapper">', '#suffix' => '</div>'); $form['info'] = array('#type' => 'fieldset', '#title' => $this->t('General Information'), '#tree' => FALSE, '#weight' => 2, '#prefix' => "<div id='features-export-info'>", '#suffix' => '</div>'); $form['info']['name'] = array('#title' => $this->t('Name'), '#description' => $this->t('Example: Image gallery') . ' (' . $this->t('Do not begin name with numbers.') . ')', '#type' => 'textfield', '#default_value' => $this->package->getName()); if (!$bundle->isDefault()) { $form['info']['name']['#description'] .= '<br/>' . $this->t('The namespace "@name_" will be prepended to the machine name', array('@name' => $bundle->getMachineName())); } $form['info']['machine_name'] = array('#type' => 'machine_name', '#title' => $this->t('Machine-readable name'), '#description' => $this->t('Example: image_gallery') . ' ' . $this->t('May only contain lowercase letters, numbers and underscores.'), '#required' => TRUE, '#default_value' => $bundle->getShortName($this->package->getMachineName()), '#machine_name' => array('source' => array('info', 'name'), 'exists' => array($this, 'featureExists'))); if (!$bundle->isDefault()) { $form['info']['machine_name']['#description'] .= '<br/>' . $this->t('NOTE: Do NOT include the namespace prefix "@name_"; it will be added automatically.', array('@name' => $bundle->getMachineName())); } $form['info']['description'] = array('#title' => $this->t('Description'), '#description' => $this->t('Provide a short description of what users should expect when they install your feature.'), '#type' => 'textarea', '#rows' => 3, '#default_value' => $this->package->getDescription()); $form['info']['package'] = array('#title' => $this->t('Bundle'), '#type' => 'select', '#options' => $this->assigner->getBundleOptions(), '#default_value' => $bundle->getMachineName(), '#ajax' => array('callback' => '::updateBundle', 'wrapper' => 'features-export-info')); $form['info']['version'] = array('#title' => $this->t('Version'), '#description' => $this->t('Examples: 8.x-1.0, 8.x-1.0-beta1'), '#type' => 'textfield', '#required' => FALSE, '#default_value' => $this->package->getVersion(), '#size' => 30); $require_all = $this->package->getRequiredAll(); $form['info']['require_all'] = array('#type' => 'checkbox', '#title' => $this->t('Mark all config as required'), '#default_value' => $this->package->getRequiredAll(), '#description' => $this->t('Required config will be assigned to this feature regardless of other assignment plugins.')); $form['conflicts'] = array('#type' => 'checkbox', '#title' => $this->t('Allow conflicts'), '#default_value' => $this->allowConflicts, '#description' => $this->t('Allow configuration to be exported to more than one feature.'), '#weight' => 8, '#ajax' => array('callback' => '::updateForm', 'wrapper' => 'features-edit-wrapper')); $generation_info = array(); if (\Drupal::currentUser()->hasPermission('export configuration')) { // Offer available generation methods. $generation_info = $this->generator->getGenerationMethods(); // Sort generation methods by weight. uasort($generation_info, '\\Drupal\\Component\\Utility\\SortArray::sortByWeightElement'); } $form['actions'] = array('#type' => 'actions', '#tree' => TRUE); foreach ($generation_info as $method_id => $method) { $form['actions'][$method_id] = array('#type' => 'submit', '#name' => $method_id, '#value' => $this->t('@name', array('@name' => $method['name'])), '#attributes' => array('title' => SafeMarkup::checkPlain($method['description']))); } // Build the Component Listing panel on the right. $form['export'] = $this->buildComponentList($form_state); $form['#attached'] = array('library' => array('features_ui/drupal.features_ui.admin'), 'drupalSettings' => array('features' => array('excluded' => $this->excluded, 'required' => $this->required, 'conflicts' => $this->conflicts, 'autodetect' => TRUE))); return $form; }