diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php index 20858b9264a05acf1aacd38e1c75f9c11e34f28b..d0fc0a3ec71174166c0be0e05ea2258afa56e68b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php @@ -228,7 +228,7 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ '#type' => 'hidden', // Yes, default_value on a hidden. It needs to be changeable by the // javascript. - '#default_value' => $term->parent->value, + '#default_value' => $term->parents[0], '#attributes' => array( 'class' => array('term-parent'), ), @@ -387,12 +387,12 @@ public function submitForm(array &$form, array &$form_state) { $weight = 0; $term = $tree[0]; while ($term->id() != $form['#first_tid']) { - if ($term->parent->value == 0 && $term->weight->value != $weight) { + if ($term->parents[0] == 0 && $term->weight->value != $weight) { $term->weight->value = $weight; $changed_terms[$term->id()] = $term; } $weight++; - $hierarchy = $term->parent->value != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; + $hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; $term = $tree[$weight]; } @@ -408,18 +408,18 @@ public function submitForm(array &$form, array &$form_state) { } // Terms not at the root level can safely start from 0 because they're all on this page. elseif ($values['term']['parent'] > 0) { - $level_weights[$values['term']['parent']] = isset($level_weights[$values['term']['parent']]) ? $level_weights[$values['term']->parent->value] + 1 : 0; + $level_weights[$values['term']['parent']] = isset($level_weights[$values['term']['parent']]) ? $level_weights[$values['term']['parent']] + 1 : 0; if ($level_weights[$values['term']['parent']] != $term->weight->value) { $term->weight->value = $level_weights[$values['term']['parent']]; $changed_terms[$term->id()] = $term; } } // Update any changed parents. - if ($values['term']['parent'] != $term->parent->value) { + if ($values['term']['parent'] != $term->parents[0]) { $term->parent->value = $values['term']['parent']; $changed_terms[$term->id()] = $term; } - $hierarchy = $term->parent->value != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; + $hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; $weight++; } } @@ -427,12 +427,12 @@ public function submitForm(array &$form, array &$form_state) { // Build a list of all terms that need to be updated on following pages. for ($weight; $weight < count($tree); $weight++) { $term = $tree[$weight]; - if ($term->parent->value == 0 && $term->weight->value != $weight) { - $term->parent->value = $term->parent->value; + if ($term->parents[0] == 0 && $term->weight->value != $weight) { + $term->parent->value = $term->parents[0]; $term->weight->value = $weight; $changed_terms[$term->id()] = $term; } - $hierarchy = $term->parent->value != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; + $hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy; } // Save all updated terms. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermIndentationTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermIndentationTest.php index 7722a165d5f1800684471fdc6325ada5456ceb21..94abb71945ffe5d0a59e6809e91583931d429784 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermIndentationTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermIndentationTest.php @@ -54,6 +54,27 @@ function testTermIndentation() { // Submit the edited form and check for HTML indentation element presence. $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid'), $edit, t('Save')); $this->assertPattern('|<div class="indentation"> </div>|'); + + // Check explicitly that term 2's parent is term 1. + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent'); + + // Move the second term back out to the root level. + $edit = array( + 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2, + 'terms[tid:' . $term2->id() . ':0][term][parent]' => '', + 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0, + 'terms[tid:' . $term2->id() . ':0][weight]' => 1, + ); + + $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid'), $edit, t('Save')); + // All terms back at the root level, no identation should be present. + $this->assertNoPattern('|<div class="indentation"> </div>|'); + + // Check explicitly that term 2 has no parents. + drupal_static_reset(); + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertTrue(empty($parents), 'Term 2 has no parents now'); } }