diff --git a/core/modules/taxonomy/css/taxonomy.theme.css b/core/modules/taxonomy/css/taxonomy.theme.css deleted file mode 100644 index 543666a..0000000 --- a/core/modules/taxonomy/css/taxonomy.theme.css +++ /dev/null @@ -1,10 +0,0 @@ - -.taxonomy-term-preview { - background-color: #eee; -} -.taxonomy-term-divider-top { - border-bottom: none; -} -.taxonomy-term-divider-bottom { - border-top: 1px dotted #ccc; -} diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index 9e7e391..43d0cf4 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -89,94 +89,30 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular $page = $this->getRequest()->query->get('page') ?: 0; // Number of terms per page. $page_increment = $this->config('taxonomy.settings')->get('terms_per_page_admin'); - // Elements shown on this page. - $page_entries = 0; - // Elements at the root level before this page. - $before_entries = 0; - // Elements at the root level after this page. - $after_entries = 0; - // Elements at the root level on this page. - $root_entries = 0; - - // Terms from previous and next pages are shown if the term tree would have - // been cut in the middle. Keep track of how many extra terms we show on - // each page of terms. - $back_step = NULL; - $forward_step = 0; - // An array of the terms to be displayed on this page. - $current_page = array(); - - $delta = 0; $term_deltas = array(); $tree = $this->storageController->loadTree($taxonomy_vocabulary->id(), 0, NULL, TRUE); - $tree_index = 0; - do { - // In case this tree is completely empty. - if (empty($tree[$tree_index])) { - break; - } - $delta++; - // Count entries before the current page. - if ($page && ($page * $page_increment) > $before_entries && !isset($back_step)) { - $before_entries++; - continue; - } - // Count entries after the current page. - elseif ($page_entries > $page_increment && isset($complete_tree)) { - $after_entries++; - continue; - } - - // Do not let a term start the page that is not at the root. - $term = $tree[$tree_index]; - if (isset($term->depth) && ($term->depth > 0) && !isset($back_step)) { - $back_step = 0; - while ($pterm = $tree[--$tree_index]) { - $before_entries--; - $back_step++; - if ($pterm->depth == 0) { - $tree_index--; - // Jump back to the start of the root level parent. - continue 2; - } - } - } - $back_step = isset($back_step) ? $back_step : 0; - - // Continue rendering the tree until we reach the a new root item. - if ($page_entries >= $page_increment + $back_step + 1 && $term->depth == 0 && $root_entries > 1) { - $complete_tree = TRUE; - // This new item at the root level is the first item on the next page. - $after_entries++; - continue; - } - if ($page_entries >= $page_increment + $back_step) { - $forward_step++; - } - - // Finally, if we've gotten down this far, we're rendering a term on this - // page. - $page_entries++; + $pages = array(array()); + $page_index = 0; + foreach ($tree as $term) { $term_deltas[$term->id()] = isset($term_deltas[$term->id()]) ? $term_deltas[$term->id()] + 1 : 0; $key = 'tid:' . $term->id() . ':' . $term_deltas[$term->id()]; - - // Keep track of the first term displayed on this page. - if ($page_entries == 1) { - $form['#first_tid'] = $term->id(); - } - // Keep a variable to make sure at least 2 root elements are displayed. - if ($term->parents[0] == 0) { - $root_entries++; + if (!$term->parents[0] && count($pages[$page_index]) >= $page_increment) { + $page_index++; } - $current_page[$key] = $term; - } while (isset($tree[++$tree_index])); + $pages[$page_index][$key] = $term; + } + // An array of the terms to be displayed on this page. + $current_page = isset($pages[$page]) ? $pages[$page] : array(); + if ($current_page) { + $form['#first_tid'] = reset($current_page)->id(); + } // Because we didn't use a pager query, set the necessary pager variables. - $total_entries = $before_entries + $page_entries + $after_entries; + $total_entries = count($tree); $pager_total_items[0] = $total_entries; $pager_page_array[0] = $page; - $pager_total[0] = ceil($total_entries / $page_increment); + $pager_total[0] = count($pages); // If this form was already submitted once, it's probably hit a validation // error. Ensure the form is rebuilt in the same order as the user @@ -257,7 +193,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular } $form['terms'][$key]['weight'] = array( '#type' => 'weight', - '#delta' => $delta, + '#delta' => $total_entries, '#title' => $this->t('Weight for added term'), '#title_display' => 'invisible', '#default_value' => $term->getWeight(), @@ -294,20 +230,6 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular $form['terms'][$key]['#attributes']['class'][] = 'draggable'; } - // Add classes that mark which terms belong to previous and next pages. - if ($row_position < $back_step || $row_position >= $page_entries - $forward_step) { - $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-preview'; - } - - if ($row_position !== 0 && $row_position !== count($tree) - 1) { - if ($row_position == $back_step - 1 || $row_position == $page_entries - $forward_step - 1) { - $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-divider-top'; - } - elseif ($row_position == $back_step || $row_position == $page_entries - $forward_step) { - $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-divider-bottom'; - } - } - // Add an error class if this row contains a form error. foreach ($errors as $error_key => $error) { if (strpos($error_key, $key) === 0) { @@ -332,11 +254,6 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular 'group' => 'term-depth', 'hidden' => FALSE, ); - $form['terms']['#attached']['library'][] = 'taxonomy/drupal.taxonomy'; - $form['terms']['#attached']['drupalSettings']['taxonomy'] = [ - 'backStep' => $back_step, - 'forwardStep' => $forward_step, - ]; } $form['terms']['#tabledrag'][] = array( 'action' => 'order', diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 0cd7618..964f226 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -122,46 +122,64 @@ function testTaxonomyTermChildTerms() { $term1 = $this->createTerm($this->vocabulary); $terms_array = ''; - // Create 40 terms. Terms 1-12 get parent of $term1. All others are + // Create 30 terms. Terms 1-12 get parent of $term1. All others are // individual terms. - for ($x = 1; $x <= 40; $x++) { + for ($x = 1; $x <= 30; $x++) { $edit = array(); // Set terms in order so we know which terms will be on which pages. $edit['weight'] = $x; - // Set terms 1-20 to be children of first term created. + // Set terms 1-12 to be children of first term created. if ($x <= 12) { $edit['parent'] = $term1->id(); } $term = $this->createTerm($this->vocabulary, $edit); - $children = taxonomy_term_load_children($term1->id()); - $parents = taxonomy_term_load_parents($term->id()); $terms_array[$x] = Term::load($term->id()); } // Get Page 1. $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); $this->assertText($term1->getName(), 'Parent Term is displayed on Page 1'); - for ($x = 1; $x <= 13; $x++) { - $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 1'); + for ($x = 1; $x <= 30; $x++) { + if ($x <= 12) { + $this->assertText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' found on Page 1'); + } + else { + $this->assertNoText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' not found on Page 1'); + } } // Get Page 2. $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array('query' => array('page' => 1))); - $this->assertText($term1->getName(), 'Parent Term is displayed on Page 2'); - for ($x = 1; $x <= 18; $x++) { - $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 2'); + $this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 2'); + for ($x = 1; $x <= 30; $x++) { + if ($x > 12 && $x <= 21) { + $this->assertText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' found on Page 2'); + } + else { + $this->assertNoText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' not found on Page 2'); + } } // Get Page 3. $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array('query' => array('page' => 2))); $this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 3'); - for ($x = 1; $x <= 17; $x++) { - $this->assertNoText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' not found on Page 3'); + for ($x = 1; $x <= 30; $x++) { + if ($x > 21) { + $this->assertText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' found on Page 3'); + } + else { + $this->assertNoText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' not found on Page 3'); + } } - for ($x =18; $x <= 25; $x++) { - $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 3'); + + // Get Page 4. There is no page 4. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array('query' => array('page' => 3))); + $this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 4'); + for ($x = 1; $x <= 30; $x++) { + $this->assertNoText($terms_array[$x]->getName(), "term $x " . $terms_array[$x]->getName() . ' not found on Page 4'); } + } /** diff --git a/core/modules/taxonomy/taxonomy.js b/core/modules/taxonomy/taxonomy.js deleted file mode 100644 index 8ffe502..0000000 --- a/core/modules/taxonomy/taxonomy.js +++ /dev/null @@ -1,45 +0,0 @@ -(function ($) { - - "use strict"; - - /** - * Move a block in the blocks table from one region to another via select list. - * - * This behavior is dependent on the tableDrag behavior, since it uses the - * objects initialized in that behavior to update the row. - */ - Drupal.behaviors.termDrag = { - attach: function (context, settings) { - var backStep = settings.taxonomy.backStep; - var forwardStep = settings.taxonomy.forwardStep; - var tableDrag = Drupal.tableDrag.taxonomy; // Get the blocks tableDrag object. - var $table = $('#taxonomy'); - var rows = $table.find('tr').length; - - // When a row is swapped, keep previous and next page classes set. - tableDrag.row.prototype.onSwap = function (swappedRow) { - $table.find('tr.taxonomy-term-preview').removeClass('taxonomy-term-preview'); - $table.find('tr.taxonomy-term-divider-top').removeClass('taxonomy-term-divider-top'); - $table.find('tr.taxonomy-term-divider-bottom').removeClass('taxonomy-term-divider-bottom'); - - var tableBody = $table[0].tBodies[0]; - if (backStep) { - for (var n = 0; n < backStep; n++) { - $(tableBody.rows[n]).addClass('taxonomy-term-preview'); - } - $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top'); - $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom'); - } - - if (forwardStep) { - for (var k = rows - forwardStep - 1; k < rows - 1; k++) { - $(tableBody.rows[k]).addClass('taxonomy-term-preview'); - } - $(tableBody.rows[rows - forwardStep - 2]).addClass('taxonomy-term-divider-top'); - $(tableBody.rows[rows - forwardStep - 1]).addClass('taxonomy-term-divider-bottom'); - } - }; - } - }; - -})(jQuery); diff --git a/core/modules/taxonomy/taxonomy.libraries.yml b/core/modules/taxonomy/taxonomy.libraries.yml deleted file mode 100644 index 3a7904f..0000000 --- a/core/modules/taxonomy/taxonomy.libraries.yml +++ /dev/null @@ -1,12 +0,0 @@ -drupal.taxonomy: - version: VERSION - js: - taxonomy.js: {} - css: - component: - css/taxonomy.theme.css: {} - dependencies: - - core/jquery - - core/drupal - - core/drupalSettings - - core/drupal.tabledrag