diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index 290b257..040297f 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -240,8 +240,7 @@ function testForum() { function testAddOrphanTopic() { // Must remove forum topics to test creating orphan topics. $vid = config('forum.settings')->get('vocabulary'); - $tree = taxonomy_get_tree($vid); - taxonomy_term_delete_multiple(array_keys(taxonomy_term_load_multiple(NULL))); + taxonomy_term_delete_multiple(array_keys(entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vid)))); // Create an orphan forum item. $this->drupalLogin($this->admin_user); diff --git a/core/modules/path/lib/Drupal/path/Type/PathItem.php b/core/modules/path/lib/Drupal/path/Type/PathItem.php new file mode 100644 index 0000000..fde8386 --- /dev/null +++ b/core/modules/path/lib/Drupal/path/Type/PathItem.php @@ -0,0 +1,43 @@ + 'string', + 'label' => t('Path alias'), + ); + static::$propertyDefinitions['pid'] = array( + 'type' => 'integer', + 'label' => t('Path id'), + ); + } + return static::$propertyDefinitions; + } +} diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 2d5a03e..ee286f1 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -265,18 +265,46 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) { } /** + * Implements hook_data_type_info(). + */ +function path_data_type_info() { + $info['path_field'] = array( + 'label' => t('Path field item'), + 'description' => t('An entity field containing a path alias and related data.'), + 'class' => '\Drupal\path\Type\PathItem', + 'list class' => '\Drupal\Core\Entity\Field\Type\Field', + ); + return $info; +} + +/** + * Implements hook_entity_field_info(). + */ +function path_entity_field_info($entity_type) { + if ($entity_type == 'taxonomy_term') { + $info['definitions']['path'] = array( + 'type' => 'path_field', + 'label' => t('The path alias'), + 'computed' => TRUE, + 'list' => TRUE, + ); + return $info; + } +} + +/** * Implements hook_taxonomy_term_insert(). */ function path_taxonomy_term_insert(Term $term) { + debug($term->getPropertyDefinitions()); if (isset($term->path)) { - $path = $term->path; - $path['alias'] = trim($path['alias']); + $term->path->alias = trim($term->path->alias); // Only save a non-empty alias. - if (!empty($path['alias'])) { + if (!empty($term->path->alias)) { // Ensure fields for programmatic executions. - $path['source'] = 'taxonomy/term/' . $term->id(); - $path['langcode'] = LANGUAGE_NOT_SPECIFIED; - drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode']); + $source = 'taxonomy/term/' . $term->id(); + $langcode = LANGUAGE_NOT_SPECIFIED; + drupal_container()->get('path.crud')->save($source, $term->path->alias, $langcode); } } } @@ -286,19 +314,18 @@ function path_taxonomy_term_insert(Term $term) { */ function path_taxonomy_term_update(Term $term) { if (isset($term->path)) { - $path = $term->path; - $path['alias'] = trim($path['alias']); + $term->path->alias = trim($term->path->alias); // Delete old alias if user erased it. - if (!empty($path['pid']) && empty($path['alias'])) { - drupal_container()->get('path.crud')->delete(array('pid' => $path['pid'])); + if (!empty($term->path->pid) && empty($term->path->alias)) { + drupal_container()->get('path.crud')->delete(array('pid' => $term->path->pid)); } // Only save a non-empty alias. - if (!empty($path['alias'])) { - $pid = (!empty($path['pid']) ? $path['pid'] : NULL); + if ($term->path->alias) { + $pid = (!empty($term->path->pid) ? $term->path->pid : NULL); // Ensure fields for programmatic executions. - $path['source'] = 'taxonomy/term/' . $term->id(); - $path['langcode'] = LANGUAGE_NOT_SPECIFIED; - drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode'], $pid); + $source = 'taxonomy/term/' . $term->id(); + $langcode = LANGUAGE_NOT_SPECIFIED; + drupal_container()->get('path.crud')->save($source, $term->path->alias, $langcode, $pid); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php index 40a3ac3..e9408a0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php @@ -114,7 +114,6 @@ class Term extends EntityNG implements ContentEntityInterface { protected $values = array( 'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))), 'weight' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), - 'parent' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), ); /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php index 18f458b..179f019 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php @@ -120,14 +120,14 @@ function pre_render(&$values) { $result = $query->execute(); foreach ($result as $term) { - $this->items[$term->node_nid][$term->id()]['name'] = check_plain($term->label()); - $this->items[$term->node_nid][$term->id()]['tid'] = $term->id(); - $this->items[$term->node_nid][$term->id()]['vocabulary_vid'] = $term->bundle(); - $this->items[$term->node_nid][$term->id()]['vocabulary'] = check_plain($vocabularies[$term->bundle()]->label()); + $this->items[$term->node_nid][$term->tid]['name'] = check_plain($term->name); + $this->items[$term->node_nid][$term->tid]['tid'] = $term->tid; + $this->items[$term->node_nid][$term->tid]['vocabulary_vid'] = $term->vid; + $this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($vocabularies[$term->vid]->label()); if (!empty($this->options['link_to_taxonomy'])) { - $this->items[$term->node_nid][$term->id()]['make_link'] = TRUE; - $this->items[$term->node_nid][$term->id()]['path'] = 'taxonomy/term/' . $term->id(); + $this->items[$term->node_nid][$term->tid]['make_link'] = TRUE; + $this->items[$term->node_nid][$term->tid]['path'] = 'taxonomy/term/' . $term->tid; } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php index cc69b4f..856254a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php @@ -140,7 +140,7 @@ function value_form(&$form, &$form_state) { if ($tree) { foreach ($tree as $term) { $choice = new stdClass(); - $choice->option = array($term->id() => str_repeat('-', $term->depth) . $term->name); + $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); $options[] = $choice; } } @@ -158,7 +158,7 @@ function value_form(&$form, &$form_state) { } $result = $query->execute(); foreach ($result as $term) { - $options[$term->id()] = $term->name; + $options[$term->tid] = $term->name; } } @@ -320,7 +320,7 @@ function validate_term_strings(&$form, $values) { $result = $query->execute(); foreach ($result as $term) { unset($missing[strtolower($term->name)]); - $tids[] = $term->id(); + $tids[] = $term->tid; } if ($missing && !empty($this->options['error_message'])) { @@ -360,7 +360,7 @@ public function adminSummary() { ->condition('td.tid', $this->value) ->execute(); foreach ($result as $term) { - $this->value_options[$term->id()] = $term->name; + $this->value_options[$term->tid] = $term->name; } } return parent::adminSummary(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index b5690c0..b75b229 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -24,6 +24,9 @@ class TermStorageController extends DatabaseStorageControllerNG { * vocabulary ID ('vid') is required. */ public function create(array $values) { + if (empty($values['parent'])) { + $values['parent'] = array(0); + } $entity = parent::create($values); return $entity; } @@ -83,20 +86,27 @@ protected function postDelete($entities) { * Overrides Drupal\Core\Entity\DatabaseStorageController::postSave(). */ protected function postSave(EntityInterface $entity, $update) { - db_delete('taxonomy_term_hierarchy') - ->condition('tid', $entity->id()) - ->execute(); + // Only change the parents if a value is set, keep the existing values if + // not. They are keyed by term id if set through the UI, so take the first + // value. + $parents = $entity->parent->getValue(); + $parent = reset($parents); + if (isset($parent['value']) && $parent['value'] !== NULL) { + db_delete('taxonomy_term_hierarchy') + ->condition('tid', $entity->id()) + ->execute(); - $query = db_insert('taxonomy_term_hierarchy') - ->fields(array('tid', 'parent')); + $query = db_insert('taxonomy_term_hierarchy') + ->fields(array('tid', 'parent')); - foreach ($entity->parent as $parent) { - $query->values(array( - 'tid' => $entity->id(), - 'parent' => (int)$parent->value, - )); + foreach ($entity->parent as $parent) { + $query->values(array( + 'tid' => $entity->id(), + 'parent' => (int)$parent->value, + )); + } + $query->execute(); } - $query->execute(); } /** diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 31146f7..db12e91 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -22,9 +22,10 @@ function taxonomy_term_page(Term $term) { // @todo This overrides any other possible breadcrumb and is a pure hard-coded // presumption. Make this behavior configurable per vocabulary or term. $breadcrumb = array(); - while ($parents = taxonomy_term_load_parents($term->id())) { - $term = array_shift($parents); - $breadcrumb[] = l($term->label(), 'taxonomy/term/' . $term->id()); + $current = $term; + while ($parents = taxonomy_term_load_parents($current->id())) { + $current = array_shift($parents); + $breadcrumb[] = l($term->label(), 'taxonomy/term/' . $current->id()); } $breadcrumb[] = l(t('Home'), NULL); $breadcrumb = array_reverse($breadcrumb);