Skip to content
Snippets Groups Projects
Commit 6ca86d9f authored by catch's avatar catch
Browse files

Issue #2049121 by plopesc, klausi: Regression: Moving out term children on...

Issue #2049121 by plopesc, klausi: Regression: Moving out term children on term listing page is broken.
parent 5ca372cb
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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.
......
......@@ -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">&nbsp;</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">&nbsp;</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');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment