diff --git a/modules/features_ui/src/Form/AssignmentBaseForm.php b/modules/features_ui/src/Form/AssignmentBaseForm.php index 9a3295b..b1b30cb 100644 --- a/modules/features_ui/src/Form/AssignmentBaseForm.php +++ b/modules/features_ui/src/Form/AssignmentBaseForm.php @@ -55,10 +55,9 @@ class AssignmentBaseForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $settings = array( - 'types' => $form_state->getValue('types'), - ); - + // Merge in types selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + $settings['types'] = $form_state->getValue('types'); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); $this->setRedirect($form_state); diff --git a/modules/features_ui/src/Form/AssignmentConfigureForm.php b/modules/features_ui/src/Form/AssignmentConfigureForm.php index a4b8a77..ac6ca18 100644 --- a/modules/features_ui/src/Form/AssignmentConfigureForm.php +++ b/modules/features_ui/src/Form/AssignmentConfigureForm.php @@ -11,6 +11,8 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\features\FeaturesManagerInterface; use Drupal\features\FeaturesAssignerInterface; +use Drupal\features\Entity\FeaturesBundle; +use Drupal\features\FeaturesBundleInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -23,6 +25,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class AssignmentConfigureForm extends FormBase { /** + * Bundle select value that should trigger a new bundle to be created. + */ + const NEW_BUNDLE_SELECT_VALUE = 'new'; + + /** * The features manager. * * @var \Drupal\features\FeaturesManagerInterface @@ -72,13 +79,22 @@ class AssignmentConfigureForm extends FormBase { * @param $bundle_name * @param \Drupal\Core\Form\FormStateInterface $form_state */ - protected function loadBundleValues(FormStateInterface &$form_state, $current_bundle, $enabled_methods, $methods_weight) { + protected function loadBundleValues($bundle_name, FormStateInterface &$form_state, $current_bundle, $enabled_methods, $methods_weight) { $input = $form_state->getUserInput(); - $input['bundle']['name'] = $current_bundle->isDefault() ? '' : $current_bundle->getName(); - $input['bundle']['machine_name'] = $current_bundle->getMachineName(); - $input['bundle']['description'] = $current_bundle->isDefault() ? '' : $current_bundle->getDescription(); - $input['bundle']['is_profile'] = $current_bundle->isProfile() ? 1 : null; - $input['bundle']['profile_name'] = $current_bundle->isProfile() ? $current_bundle->getProfileName() : ''; + if ($bundle_name == self::NEW_BUNDLE_SELECT_VALUE) { + $input['bundle']['name'] = ''; + $input['bundle']['machine_name'] = ''; + $input['bundle']['description'] = ''; + $input['bundle']['is_profile'] = NULL; + $input['bundle']['profile_name'] = ''; + } + else { + $input['bundle']['name'] = $current_bundle->getName(); + $input['bundle']['machine_name'] = $current_bundle->getMachineName(); + $input['bundle']['description'] = $current_bundle->getDescription(); + $input['bundle']['is_profile'] = $current_bundle->isProfile() ? 1 : null; + $input['bundle']['profile_name'] = $current_bundle->isProfile() ? $current_bundle->getProfileName() : ''; + } foreach ($methods_weight as $method_id => $weight) { $enabled = isset($enabled_methods[$method_id]); @@ -117,12 +133,16 @@ class AssignmentConfigureForm extends FormBase { if (!isset($trigger) && ($real_trigger == 'bundle[bundle_select]')) { $input = $form_state->getUserInput(); $bundle_name = $input['bundle']['bundle_select']; - $this->assigner->setCurrent($this->assigner->getBundle($bundle_name)); + if ($bundle_name != self::NEW_BUNDLE_SELECT_VALUE) { + $this->assigner->setCurrent($this->assigner->getBundle($bundle_name)); + } $load_values = TRUE; } elseif ($trigger['#name'] == 'bundle[bundle_select]') { $bundle_name = $form_state->getValue(array('bundle', 'bundle_select')); - $this->assigner->setCurrent($this->assigner->getBundle($bundle_name)); + if ($bundle_name != self::NEW_BUNDLE_SELECT_VALUE) { + $this->assigner->setCurrent($this->assigner->getBundle($bundle_name)); + } $load_values = TRUE; } elseif ($trigger['#name'] == 'removebundle') { @@ -131,7 +151,21 @@ class AssignmentConfigureForm extends FormBase { $this->assigner->removeBundle($bundle_name); return $this->redirect('features.assignment', array('')); } - $current_bundle = $this->assigner->loadBundle($bundle_name); + if (!isset($current_bundle)) { + switch ($bundle_name) { + // If no bundle is selected, use the current one. + case NULL: + $current_bundle = $this->assigner->loadBundle(); + $bundle_name = $current_bundle->getMachineName(); + break; + case self::NEW_BUNDLE_SELECT_VALUE: + $current_bundle = $this->assigner->loadBundle(FeaturesBundleInterface::DEFAULT_BUNDLE); + break; + default: + $current_bundle = $this->assigner->loadBundle($bundle_name); + break; + } + } $settings = $current_bundle->getSettings(); $enabled_methods = $current_bundle->getEnabledAssignments(); @@ -148,7 +182,7 @@ class AssignmentConfigureForm extends FormBase { asort($methods_weight); if ($load_values) { - $this->loadBundleValues($form_state, $current_bundle, $enabled_methods, $methods_weight); + $this->loadBundleValues($bundle_name, $form_state, $current_bundle, $enabled_methods, $methods_weight); } $form = array( @@ -174,19 +208,41 @@ class AssignmentConfigureForm extends FormBase { '#weight' => -9, ); + if ($bundle_name == self::NEW_BUNDLE_SELECT_VALUE) { + $default_values = [ + 'bundle_select' => self::NEW_BUNDLE_SELECT_VALUE, + 'name' => '', + 'machine_name' => '', + 'description' => '', + 'is_profile' => FALSE, + 'profile_name' => '', + ]; + } + else { + $default_values = [ + 'bundle_select' => $current_bundle->getMachineName(), + 'name' => $current_bundle->getName(), + 'machine_name' => $current_bundle->getMachineName(), + 'description' => $current_bundle->getDescription(), + 'is_profile' => $current_bundle->isProfile(), + 'profile_name' => $current_bundle->getProfileName(), + ]; + } $form['bundle']['bundle_select'] = array( '#title' => t('Bundle'), '#title_display' => 'invisible', '#type' => 'select', - '#options' => $this->assigner->getBundleOptions(t('--New--')), - '#default_value' => $current_bundle->getMachineName(), + '#options' => [self::NEW_BUNDLE_SELECT_VALUE => t('--New--')] + $this->assigner->getBundleOptions(), + '#default_value' => $default_values['bundle_select'], '#ajax' => array( 'callback' => '::updateForm', 'wrapper' => 'edit-bundles-wrapper', ), ); - if (!$current_bundle->isDefault()) { + // Don't show the remove button for the default bundle or when adding a new + // bundle. + if ($bundle_name != self::NEW_BUNDLE_SELECT_VALUE && !$current_bundle->isDefault()) { $form['bundle']['remove'] = array( '#type' => 'button', '#name' => 'removebundle', @@ -198,25 +254,36 @@ class AssignmentConfigureForm extends FormBase { '#title' => $this->t('Bundle name'), '#type' => 'textfield', '#description' => $this->t('A unique human-readable name of this bundle.'), - '#default_value' => $current_bundle->isDefault() ? '' : $current_bundle->getName(), + '#default_value' => $default_values['name'], + '#required' => TRUE, + '#disabled' => $bundle_name == FeaturesBundleInterface::DEFAULT_BUNDLE, ); - $form['bundle']['machine_name'] = array( - '#title' => $this->t('Machine name'), - '#type' => 'machine_name', - '#required' => FALSE, - '#default_value' => $current_bundle->getMachineName(), - '#description' => $this->t('A unique machine-readable name of this bundle. Used to prefix exported packages. It must only contain lowercase letters, numbers, and underscores.'), - '#machine_name' => array( - 'source' => array('bundle', 'name'), - 'exists' => array($this, 'bundleExists'), - ), - ); + // Don't allow changing the default bundle machine name. + if ($bundle_name == FeaturesBundleInterface::DEFAULT_BUNDLE) { + $form['bundle']['machine_name'] = array( + '#type' => 'value', + '#value' => $default_values['machine_name'], + ); + } + else { + $form['bundle']['machine_name'] = array( + '#title' => $this->t('Machine name'), + '#type' => 'machine_name', + '#required' => TRUE, + '#default_value' => $default_values['machine_name'], + '#description' => $this->t('A unique machine-readable name of this bundle. Used to prefix exported packages. It must only contain lowercase letters, numbers, and underscores.'), + '#machine_name' => array( + 'source' => array('bundle', 'name'), + 'exists' => array($this, 'bundleExists'), + ), + ); + } $form['bundle']['description'] = array( '#title' => $this->t('Distribution description'), '#type' => 'textfield', - '#default_value' => $current_bundle->isDefault() ? '' : $current_bundle->getDescription(), + '#default_value' => $default_values['description'], '#description' => $this->t('A description of the bundle.'), '#size' => 80, ); @@ -224,7 +291,7 @@ class AssignmentConfigureForm extends FormBase { $form['bundle']['is_profile'] = array( '#type' => 'checkbox', '#title' => t('Include install profile'), - '#default_value' => $current_bundle->isProfile(), + '#default_value' => $default_values['is_profile'], '#description' => $this->t('Select this option to have your features packaged into an install profile.'), '#attributes' => array( 'data-add-profile' => 'status', @@ -243,7 +310,7 @@ class AssignmentConfigureForm extends FormBase { $form['bundle']['profile_name'] = array( '#title' => $this->t('Profile name'), '#type' => 'textfield', - '#default_value' => $current_bundle->isProfile() ? $current_bundle->getProfileName() : '', + '#default_value' => $default_values['profile_name'], '#description' => $this->t('The machine name (directory name) of your profile.'), '#size' => 30, // Show and require only if the profile.add option is selected. @@ -341,20 +408,31 @@ class AssignmentConfigureForm extends FormBase { $method_weights = $form_state->getValue('weight'); ksort($method_weights); - $current_bundle = $this->assigner->getBundle(); - $old_name = $current_bundle->getMachineName(); - $new_name = $form_state->getValue(array('bundle', 'machine_name')); - if ($old_name != $new_name) { - $current_bundle = $this->assigner->renameBundle($old_name, $new_name); + $machine_name = $form_state->getValue(array('bundle', 'machine_name')); + + // If this is a new bundle, create it. + if ($form_state->getValue(array('bundle', 'bundle_select')) == self::NEW_BUNDLE_SELECT_VALUE) { + $bundle = $this->assigner->createBundleFromDefault($machine_name); } - $current_bundle->setName($form_state->getValue(array('bundle', 'name'))); - $current_bundle->setDescription($form_state->getValue(array('bundle', 'description'))); - $current_bundle->setEnabledAssignments(array_keys($enabled_methods)); - $current_bundle->setAssignmentWeights($method_weights); - $current_bundle->setIsProfile($form_state->getValue(array('bundle', 'is_profile'))); - $current_bundle->setProfileName($form_state->getValue(array('bundle', 'profile_name'))); - $current_bundle->save(); - $this->assigner->setBundle($current_bundle); + // Otherwise, load the current bundle and rename if needed. + else { + $bundle = $this->assigner->getBundle(); + $old_name = $bundle->getMachineName(); + $new_name = $form_state->getValue(array('bundle', 'machine_name')); + if ($old_name != $new_name) { + $bundle = $this->assigner->renameBundle($old_name, $new_name); + } + } + + $bundle->setName($form_state->getValue(array('bundle', 'name'))); + $bundle->setDescription($form_state->getValue(array('bundle', 'description'))); + $bundle->setEnabledAssignments(array_keys($enabled_methods)); + $bundle->setAssignmentWeights($method_weights); + $bundle->setIsProfile($form_state->getValue(array('bundle', 'is_profile'))); + $bundle->setProfileName($form_state->getValue(array('bundle', 'profile_name'))); + $bundle->save(); + $this->assigner->setBundle($bundle); + $this->assigner->setCurrent($bundle); $form_state->setRedirect('features.assignment'); drupal_set_message($this->t('Package assignment configuration saved.')); diff --git a/modules/features_ui/src/Form/AssignmentCoreForm.php b/modules/features_ui/src/Form/AssignmentCoreForm.php index df766f4..ba32775 100644 --- a/modules/features_ui/src/Form/AssignmentCoreForm.php +++ b/modules/features_ui/src/Form/AssignmentCoreForm.php @@ -48,10 +48,9 @@ class AssignmentCoreForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $settings = array( - 'types' => $form_state->getValue('types'), - ); - + // Merge in types selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + $settings['types'] = $form_state->getValue('types'); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); $this->setRedirect($form_state); diff --git a/modules/features_ui/src/Form/AssignmentExcludeForm.php b/modules/features_ui/src/Form/AssignmentExcludeForm.php index 2b9ef94..9cff3a0 100644 --- a/modules/features_ui/src/Form/AssignmentExcludeForm.php +++ b/modules/features_ui/src/Form/AssignmentExcludeForm.php @@ -99,14 +99,13 @@ class AssignmentExcludeForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $types = $form_state->getValue('types'); - $curated = $form_state->getValue('curated'); - $module = $form_state->getValue('module'); - $settings = array( - 'types' => $types, - 'curated' => $curated, - 'module' => $module, - ); + // Merge in selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + $settings = array_merge($settings, [ + 'types' => $form_state->getValue('types'), + 'curated' => $form_state->getValue('curated'), + 'module' => $form_state->getValue('module'), + ]); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); diff --git a/modules/features_ui/src/Form/AssignmentOptionalForm.php b/modules/features_ui/src/Form/AssignmentOptionalForm.php index f63d372..a97ef69 100644 --- a/modules/features_ui/src/Form/AssignmentOptionalForm.php +++ b/modules/features_ui/src/Form/AssignmentOptionalForm.php @@ -48,10 +48,9 @@ class AssignmentOptionalForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $settings = array( - 'types' => $form_state->getValue('types'), - ); - + // Merge in types selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + $settings['types'] = $form_state->getValue('types'); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); $this->setRedirect($form_state); diff --git a/modules/features_ui/src/Form/AssignmentProfileForm.php b/modules/features_ui/src/Form/AssignmentProfileForm.php index 0315925..d7a8016 100644 --- a/modules/features_ui/src/Form/AssignmentProfileForm.php +++ b/modules/features_ui/src/Form/AssignmentProfileForm.php @@ -76,11 +76,14 @@ class AssignmentProfileForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $settings = array( + // Merge in selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + + $settings = array_merge($settings, [ 'curated' => $form_state->getValue('curated'), 'standard' => $form_state->getValue('standard'), 'types' => $form_state->getValue('types'), - ); + ]); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); $this->setRedirect($form_state); diff --git a/modules/features_ui/src/Form/AssignmentSiteForm.php b/modules/features_ui/src/Form/AssignmentSiteForm.php index 8d0cf52..6978d70 100644 --- a/modules/features_ui/src/Form/AssignmentSiteForm.php +++ b/modules/features_ui/src/Form/AssignmentSiteForm.php @@ -48,10 +48,9 @@ class AssignmentSiteForm extends AssignmentFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $settings = array( - 'types' => $form_state->getValue('types'), - ); - + // Merge in types selections. + $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID); + $settings['types'] = $form_state->getValue('types'); $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save(); $this->setRedirect($form_state); diff --git a/modules/features_ui/src/Form/FeaturesExportForm.php b/modules/features_ui/src/Form/FeaturesExportForm.php index bc9dc19..a93e4a7 100644 --- a/modules/features_ui/src/Form/FeaturesExportForm.php +++ b/modules/features_ui/src/Form/FeaturesExportForm.php @@ -159,7 +159,7 @@ class FeaturesExportForm extends FormBase { $form['header']['bundle'] = array( '#title' => t('Bundle'), '#type' => 'select', - '#options' => $this->assigner->getBundleOptions(t('--None--')), + '#options' => $this->assigner->getBundleOptions(), '#default_value' => $current_bundle->getMachineName(), '#prefix' => '
', '#suffix' => '
', diff --git a/src/Entity/FeaturesBundle.php b/src/Entity/FeaturesBundle.php index 7ea28aa..5af887b 100644 --- a/src/Entity/FeaturesBundle.php +++ b/src/Entity/FeaturesBundle.php @@ -87,16 +87,15 @@ class FeaturesBundle extends ConfigEntityBase implements FeaturesBundleInterface protected $is_profile; public function id() { - // @todo Convert it to $this->id on the longrun. + // @todo Convert it to $this->id in the long run. return $this->getMachineName(); } - /** * {@inheritdoc} */ public function isDefault() { - return $this->machine_name == 'default'; + return $this->machine_name == static::DEFAULT_BUNDLE; } /** @@ -253,7 +252,7 @@ class FeaturesBundle extends ConfigEntityBase implements FeaturesBundleInterface /** * {@inheritdoc} */ - public function getAssignmentSettings($method_id) { + public function getAssignmentSettings($method_id = NULL) { if (isset($method_id)) { if (isset($this->assignments[$method_id])) { return $this->assignments[$method_id]; @@ -274,9 +273,7 @@ class FeaturesBundle extends ConfigEntityBase implements FeaturesBundleInterface */ public function setAssignmentSettings($method_id, array $settings) { if (isset($method_id)) { - if (isset($this->assignments[$method_id])) { - $this->assignments[$method_id] = $settings; - } + $this->assignments[$method_id] = $settings; } else { foreach ($settings as $method_id => $method_settings) { diff --git a/src/FeaturesAssigner.php b/src/FeaturesAssigner.php index 75886bf..2eaad11 100644 --- a/src/FeaturesAssigner.php +++ b/src/FeaturesAssigner.php @@ -9,6 +9,7 @@ namespace Drupal\features; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\features\Entity\FeaturesBundle; +use Drupal\features\FeaturesBundleInterface; use Drupal\features\FeaturesManagerInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -21,8 +22,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; class FeaturesAssigner implements FeaturesAssignerInterface { use StringTranslationTrait; - const DEFAULTBUNDLE = 'default'; - /** * The package assignment method plugin manager. * @@ -93,7 +92,7 @@ class FeaturesAssigner implements FeaturesAssignerInterface { $this->configFactory = $config_factory; $this->configStorage = $config_storage; $this->bundles = $this->getBundleList(); - $this->currentBundle = $this->getBundle(self::DEFAULTBUNDLE); + $this->currentBundle = $this->getBundle(FeaturesBundleInterface::DEFAULT_BUNDLE); // Ensure bundle information is fresh. $this->createBundlesFromPackages(); } @@ -282,11 +281,10 @@ class FeaturesAssigner implements FeaturesAssignerInterface { /** * {@inheritdoc} */ - public function createBundle($name, $machine_name = NULL, $description = NULL, $is_profile = FALSE, $profile_name = NULL) { - $bundle = FeaturesBundle::create([]); - if (empty($machine_name)) { - $machine_name = strtolower(str_replace(array(' ', '-'), '_', $name)); - } + public function createBundleFromDefault($machine_name, $name = NULL, $description = NULL, $is_profile = FALSE, $profile_name = NULL) { + // Clone the default bundle to get its default configuration. + $bundle = clone $this->getBundle(FeaturesBundleInterface::DEFAULT_BUNDLE); + $bundle->setMachineName($machine_name); $bundle->setName($name); if (isset($description)) { @@ -343,7 +341,7 @@ class FeaturesAssigner implements FeaturesAssignerInterface { } } foreach ($new_bundles as $new_bundle) { - $new_bundle = $this->createBundle($new_bundle['name'], $new_bundle['machine_name'], $new_bundle['description'], $new_bundle['is_profile']); + $new_bundle = $this->createBundleFromDefault($new_bundle['name'], $new_bundle['machine_name'], $new_bundle['description'], $new_bundle['is_profile']); drupal_set_message($this->t('Features bundle @name automatically created.', ['@name' => $new_bundle->getName()])); } @@ -352,11 +350,14 @@ class FeaturesAssigner implements FeaturesAssignerInterface { /** * {@inheritdoc} */ - public function getBundleOptions($default_name = NULL) { + public function getBundleOptions($none_text = NULL) { $list = $this->getBundleList(); $result = array(); + if (isset($empty_name)) { + $result[''] = $empty_name; + } foreach ($list as $machine_name => $bundle) { - $result[$machine_name] = (isset($default_name) && $bundle->isDefault()) ? $default_name : $bundle->getName(); + $result[$machine_name] = $bundle->getName(); } return $result; } @@ -401,13 +402,13 @@ class FeaturesAssigner implements FeaturesAssignerInterface { if (!isset($machine_name)) { $session = \Drupal::request()->getSession(); if (isset($session)) { - $machine_name = isset($session) ? $session->get('features_current_bundle', '') : ''; + $machine_name = isset($session) ? $session->get('features_current_bundle', FeaturesBundleInterface::DEFAULT_BUNDLE) : FeaturesBundleInterface::DEFAULT_BUNDLE; } } $bundle = $this->getBundle($machine_name); if (!isset($bundle)) { // If bundle no longer exists then return default. - $bundle = $this->bundles[self::DEFAULTBUNDLE]; + $bundle = $this->bundles[FeaturesBundleInterface::DEFAULT_BUNDLE]; } return $this->setCurrent($bundle); } diff --git a/src/FeaturesAssignerInterface.php b/src/FeaturesAssignerInterface.php index a07bbd5..83320c6 100644 --- a/src/FeaturesAssignerInterface.php +++ b/src/FeaturesAssignerInterface.php @@ -7,6 +7,8 @@ namespace Drupal\features; +use Drupal\features\FeaturesBundleInterface; + /** * Common interface for features assignment services. * @@ -147,12 +149,12 @@ interface FeaturesAssignerInterface { public function findBundleByName($name); /** - * Creates a new bundle. + * Creates a new bundle by cloning the default bundle and customizing. * - * @param string $name - * Human readable name of the bundle. * @param string $machine_name - * Machine name. If omitted, auto-generated from Name. + * Machine name. + * @param string $name + * (optional) Human readable name of the bundle. * @param string $description * (optional) Description of the bundle. * @param bool $is_profile @@ -163,7 +165,7 @@ interface FeaturesAssignerInterface { * @return \Drupal\features\FeaturesBundleInterface * A features bundle object. */ - public function createBundle($name, $machine_name = '', $description = '', $is_profile = FALSE, $profile_name = NULL); + public function createBundleFromDefault($name, $machine_name = '', $description = '', $is_profile = FALSE, $profile_name = NULL); /** * Creates bundles by parsing information from installed packages. @@ -173,14 +175,14 @@ interface FeaturesAssignerInterface { /** * Returns an array of bundle names suitable for a select option list. * - * @param string $default_text - * The optional label for the default bundle in the list. + * @param string $none_text + * (optional) A label for an empty option in the list. * * @return array * An array of bundles, keyed by machine_name, with values being human * readable names. */ - public function getBundleOptions($default_text = NULL); + public function getBundleOptions($none_text = NULL); /** * Makes the named bundle the current bundle. diff --git a/src/FeaturesBundleInterface.php b/src/FeaturesBundleInterface.php index daaa9c3..c36cd91 100644 --- a/src/FeaturesBundleInterface.php +++ b/src/FeaturesBundleInterface.php @@ -17,6 +17,8 @@ use Drupal\Core\Extension\Extension; */ interface FeaturesBundleInterface { + const DEFAULT_BUNDLE = 'default'; + /** * Determines whether the current bundle is the default one. * diff --git a/tests/src/Kernel/Entity/FeaturesBundleIntegrationTest.php b/tests/src/Kernel/Entity/FeaturesBundleIntegrationTest.php index 8d0be48..da3893e 100644 --- a/tests/src/Kernel/Entity/FeaturesBundleIntegrationTest.php +++ b/tests/src/Kernel/Entity/FeaturesBundleIntegrationTest.php @@ -3,6 +3,7 @@ namespace Drupal\features\tests\src\Kernel\Entity; use Drupal\features\Entity\FeaturesBundle; +use Drupal\features\FeaturesBundleInterface; use Drupal\KernelTests\KernelTestBase; /** @@ -33,7 +34,7 @@ class FeaturesBundleIntegrationTest extends KernelTestBase { */ public function testIsDefaultWithDefaultBundle() { $bundle = FeaturesBundle::create([ - 'machine_name' => 'default', + 'machine_name' => FeaturesBundleInterface::DEFAULT_BUNDLE, ]); $this->assertTrue($bundle->isDefault());