diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/modules/taxonomy/src/TermForm.php | 20 | ||||
-rw-r--r-- | core/modules/taxonomy/tests/src/Functional/TermTest.php | 25 |
2 files changed, 37 insertions, 8 deletions
diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index e252d8e073e..73f6e4d11e1 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -63,15 +63,19 @@ class TermForm extends ContentEntityForm { $options[$item->tid] = str_repeat('-', $item->depth) . $item->name; } } - - $form['relations']['parent'] = [ - '#type' => 'select', - '#title' => $this->t('Parent terms'), - '#options' => $options, - '#default_value' => $parent, - '#multiple' => TRUE, - ]; } + else { + $options = ['<' . $this->t('root') . '>']; + $parent = [0]; + } + + $form['relations']['parent'] = [ + '#type' => 'select', + '#title' => $this->t('Parent terms'), + '#options' => $options, + '#default_value' => $parent, + '#multiple' => TRUE, + ]; $form['relations']['weight'] = [ '#type' => 'textfield', diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php index d325cb1c418..0bf4118ee9f 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php @@ -433,6 +433,31 @@ class TermTest extends TaxonomyTestBase { } /** + * Test UI with override_selector TRUE. + */ + public function testTermSaveOverrideSelector() { + $this->config('taxonomy.settings')->set('override_selector', TRUE)->save(); + + // Create a Term. + $edit = [ + 'name[0][value]' => $this->randomMachineName(12), + 'description[0][value]' => $this->randomMachineName(100), + ]; + // Create the term to edit. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); + $this->submitForm($edit, 'Save'); + $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties([ + 'name' => $edit['name[0][value]'], + ]); + $term = reset($terms); + $this->assertNotNull($term, 'Term found in database.'); + + // The term appears on the vocab list page. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); + $this->assertSession()->pageTextContains($term->getName()); + } + + /** * Save, edit and delete a term using the user interface. */ public function testTermReorder() { |