diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 708706e..2019c70 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -774,13 +774,23 @@ function entity_page_access(EntityInterface $entity, $operation = 'view') { * * @param string $entity_type * The entity type. + * @param string $bundle + * (optional) The bundle of the entity. Required if the entity supports + * bundles, defaults to the entity type otherwise. * * @return bool * TRUE if the access is granted. FALSE if access is denied. */ -function entity_page_create_access($entity_type) { +function entity_page_create_access($entity_type, $bundle = NULL) { + $definition = drupal_container()->get('plugin.manager.entity')->getDefinition($entity_type); + + // Pass in the entity bundle if given and required. + $values = array(); + if ($bundle && isset($definition['entity_keys']['bundle'])) { + $values[$definition['entity_keys']['bundle']] = $bundle; + } $entity = drupal_container()->get('plugin.manager.entity') ->getStorageController($entity_type) - ->create(array()); + ->create($values); return $entity->access('create'); } diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index 5171850..0403fb1 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -106,10 +106,10 @@ function forum_form_submit($form, &$form_state) { case SAVED_NEW: if ($container) { $containers = $config->get('containers'); - $containers[] = $term->tid; + $containers[] = $term->id(); $config->set('containers', $containers)->save(); } - $form_state['values']['tid'] = $term->tid; + $form_state['values']['tid'] = $term->id(); drupal_set_message(t('Created new @type %term.', array('%term' => $form_state['values']['name'], '@type' => $type))); break; case SAVED_UPDATED: @@ -336,7 +336,7 @@ function _forum_parent_select($tid, $title, $child_type) { $parents = taxonomy_term_load_parents($tid); if ($parents) { $parent = array_shift($parents); - $parent = $parent->tid; + $parent = $parent->id(); } else { $parent = 0; @@ -347,7 +347,7 @@ function _forum_parent_select($tid, $title, $child_type) { // A term can't be the child of itself, nor of its children. foreach ($children as $child) { - $exclude[] = $child->tid; + $exclude[] = $child->id(); } $exclude[] = $tid; @@ -355,8 +355,8 @@ function _forum_parent_select($tid, $title, $child_type) { $options[0] = '<' . t('root') . '>'; if ($tree) { foreach ($tree as $term) { - if (!in_array($term->tid, $exclude)) { - $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->label(); + if (!in_array($term->id(), $exclude)) { + $options[$term->id()] = str_repeat(' -- ', $term->depth) . $term->label(); } } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 574d536..952e98f 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -171,7 +171,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) { // Add action link to 'node/add/forum' on 'forum' sub-pages. if ($root_path == 'forum' || $root_path == 'forum/%') { - $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0); + $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->id() : 0); $forum_term = forum_forum_load($tid); if ($forum_term) { $links = array(); @@ -183,7 +183,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) { '#theme' => 'menu_local_action', '#link' => array( 'title' => t('Add new @node_type', array('@node_type' => node_type_get_label($type))), - 'href' => 'node/add/' . $type . '/' . $forum_term->tid, + 'href' => 'node/add/' . $type . '/' . $forum_term->id(), ), ); } @@ -233,7 +233,7 @@ function forum_entity_bundle_info_alter(&$bundles) { */ function forum_uri($forum) { return array( - 'path' => 'forum/' . $forum->tid, + 'path' => 'forum/' . $forum->id(), ); } @@ -266,7 +266,7 @@ function forum_node_view(EntityInterface $node, EntityDisplay $display, $view_mo if ($parents = taxonomy_term_load_parents_all($node->forum_tid)) { $parents = array_reverse($parents); foreach ($parents as $parent) { - $breadcrumb[] = l($parent->label(), 'forum/' . $parent->tid); + $breadcrumb[] = l($parent->label(), 'forum/' . $parent->id()); } } drupal_set_breadcrumb($breadcrumb); @@ -301,10 +301,10 @@ function forum_node_validate(EntityInterface $node, $form) { continue; } $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid', 0, 1, array( - ':tid' => $term->tid, + ':tid' => $term->id(), ':vid' => $term->bundle(), ))->fetchField(); - if ($used && in_array($term->tid, $containers)) { + if ($used && in_array($term->id(), $containers)) { form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->label()))); } } @@ -432,7 +432,7 @@ function forum_node_load($nodes) { ->condition('f.vid', $node_vids); $result = $query->execute(); foreach ($result as $record) { - $nodes[$record->nid]->forum_tid = $record->tid; + $nodes[$record->nid]->forum_tid = $record->id(); } } } @@ -470,7 +470,7 @@ function forum_taxonomy_term_delete(Term $term) { // For containers, remove the tid from the forum_containers variable. $config = config('forum.settings'); $containers = $config->get('containers'); - $key = array_search($term->tid, $containers); + $key = array_search($term->id(), $containers); if ($key !== FALSE) { unset($containers[$key]); } @@ -526,7 +526,7 @@ function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields) $query->values(array( 'nid' => $entity->id(), 'title' => $translation->title->value, - 'tid' => $translation->taxonomy_forums->tid, + 'tid' => $translation->taxonomy_forums->id(), 'sticky' => $entity->sticky, 'created' => $entity->created, 'comment_count' => 0, @@ -717,12 +717,12 @@ function forum_forum_load($tid = NULL) { } // Determine if the requested term is a container. - if (!$forum_term->tid || in_array($forum_term->tid, $config->get('containers'))) { + if (!$forum_term->id() || in_array($forum_term->id(), $config->get('containers'))) { $forum_term->container = 1; } // Load parent terms. - $forum_term->parents = taxonomy_term_load_parents_all($forum_term->tid); + $forum_term->parents = taxonomy_term_load_parents_all($forum_term->id()); // Load the tree below. $forums = array(); @@ -745,14 +745,14 @@ function forum_forum_load($tid = NULL) { foreach ($_forums as $forum) { // Determine if the child term is a container. - if (in_array($forum->tid, $config->get('containers'))) { + if (in_array($forum->id(), $config->get('containers'))) { $forum->container = 1; } // Merge in the topic and post counters. - if (!empty($counts[$forum->tid])) { - $forum->num_topics = $counts[$forum->tid]->topic_count; - $forum->num_posts = $counts[$forum->tid]->topic_count + $counts[$forum->tid]->comment_count; + if (!empty($counts[$forum->id()])) { + $forum->num_topics = $counts[$forum->id()]->topic_count; + $forum->num_posts = $counts[$forum->id()]->topic_count + $counts[$forum->id()]->comment_count; } else { $forum->num_topics = 0; @@ -761,7 +761,7 @@ function forum_forum_load($tid = NULL) { // Query "Last Post" information for this forum. $query = db_select('node', 'n'); - $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $forum->tid)); + $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $forum->id())); $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); $query->join('users', 'u', 'ncs.last_comment_uid = u.uid'); $query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u.name END', 'last_comment_name'); @@ -784,7 +784,7 @@ function forum_forum_load($tid = NULL) { } $forum->last_post = $last_post; - $forums[$forum->tid] = $forum; + $forums[$forum->id()] = $forum; } // Cache the result, and return the tree. @@ -1046,7 +1046,7 @@ function template_preprocess_forum_list(&$variables) { // Sanitize each forum so that the template can safely print the data. foreach ($variables['forums'] as $id => $forum) { $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : ''; - $variables['forums'][$id]->link = url("forum/$forum->tid"); + $variables['forums'][$id]->link = url("forum/$forum->id()"); $variables['forums'][$id]->name = check_plain($forum->label()); $variables['forums'][$id]->is_container = !empty($forum->container); $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; @@ -1059,10 +1059,10 @@ function template_preprocess_forum_list(&$variables) { $variables['forums'][$id]->icon_class = 'default'; $variables['forums'][$id]->icon_title = t('No new posts'); if ($user->uid) { - $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid); + $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->id(), $user->uid); if ($variables['forums'][$id]->new_topics) { $variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new post in forum %title', '@count new posts in forum %title', array('%title' => $variables['forums'][$id]->name)); - $variables['forums'][$id]->new_url = url("forum/$forum->tid", array('fragment' => 'new')); + $variables['forums'][$id]->new_url = url("forum/$forum->id()", array('fragment' => 'new')); $variables['forums'][$id]->icon_class = 'new'; $variables['forums'][$id]->icon_title = t('New posts'); } diff --git a/core/modules/forum/forum.pages.inc b/core/modules/forum/forum.pages.inc index 78eabbd..422d92e 100644 --- a/core/modules/forum/forum.pages.inc +++ b/core/modules/forum/forum.pages.inc @@ -30,21 +30,21 @@ function forum_page($forum_term = NULL) { // Breadcrumb navigation. $breadcrumb[] = l(t('Home'), NULL); - if ($forum_term->tid) { + if ($forum_term->id()) { // Parent of all forums is the vocabulary name. $breadcrumb[] = l($vocabulary->label(), 'forum'); } // Add all parent forums to breadcrumbs. if ($forum_term->parents) { foreach (array_reverse($forum_term->parents) as $parent) { - if ($parent->id() != $forum_term->tid) { + if ($parent->id() != $forum_term->id()) { $breadcrumb[] = l($parent->label(), 'forum/' . $parent->id()); } } } drupal_set_breadcrumb($breadcrumb); - if ($forum_term->tid && array_search($forum_term->tid, $config->get('containers')) === FALSE) { + if ($forum_term->id() && array_search($forum_term->id(), $config->get('containers')) === FALSE) { // Add RSS feed for forums. drupal_add_feed('taxonomy/term/' . $forum_term->id() . '/feed', 'RSS - ' . $forum_term->label()); } @@ -58,7 +58,7 @@ function forum_page($forum_term = NULL) { $sort_by = $config->get('topics.order'); if (empty($forum_term->container)) { - $topics = forum_get_topics($forum_term->tid, $sort_by, $forum_per_page); + $topics = forum_get_topics($forum_term->id(), $sort_by, $forum_per_page); } else { $topics = ''; @@ -69,7 +69,7 @@ function forum_page($forum_term = NULL) { '#forums' => $forum_term->forums, '#topics' => $topics, '#parents' => $forum_term->parents, - '#tid' => $forum_term->tid, + '#tid' => $forum_term->id(), '#sortby' => $sort_by, '#forums_per_page' => $forum_per_page, ); diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index c08ce70..d0c7c9b 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -242,7 +242,7 @@ function testAddOrphanTopic() { $vid = config('forum.settings')->get('vocabulary'); $tree = taxonomy_get_tree($vid); foreach ($tree as $term) { - taxonomy_term_delete($term->tid); + taxonomy_term_delete($term->id()); } // Create an orphan forum item. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index a9ae1c3..f9789a0 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -77,7 +77,7 @@ public function testForumPager() { // Look up the general discussion term. $tree = taxonomy_get_tree($vid, 0, 1); - $tid = reset($tree)->tid; + $tid = reset($tree)->id(); $this->assertTrue($tid, 'General discussion term is found in the forum vocabulary.'); // Create 30 nodes. diff --git a/core/modules/options/options.api.php b/core/modules/options/options.api.php index 2a303d5..1bd3e05 100644 --- a/core/modules/options/options.api.php +++ b/core/modules/options/options.api.php @@ -62,7 +62,7 @@ function hook_options_list($field, $instance, $entity) { $terms = taxonomy_get_tree($tree['vid'], $tree['parent'], NULL, TRUE); if ($terms) { foreach ($terms as $term) { - $options[$term->tid] = str_repeat('-', $term->depth) . $term->label(); + $options[$term->id()] = str_repeat('-', $term->depth) . $term->label(); } } } diff --git a/core/modules/path/path.module b/core/modules/path/path.module index b6a38f6..2d5a03e 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -235,13 +235,13 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) { // Make sure this does not show up on the delete confirmation form. if (empty($form_state['confirm_delete'])) { $term = $form_state['controller']->getEntity($form_state); - $path = (isset($term->tid) ? drupal_container()->get('path.crud')->load(array('source' => 'taxonomy/term/' . $term->tid)) : array()); + $path = ($term->id() ? drupal_container()->get('path.crud')->load(array('source' => 'taxonomy/term/' . $term->id())) : array()); if ($path === FALSE) { $path = array(); } $path += array( 'pid' => NULL, - 'source' => isset($term->tid) ? 'taxonomy/term/' . $term->tid : NULL, + 'source' => $term->id() ? 'taxonomy/term/' . $term->id() : NULL, 'alias' => '', 'langcode' => LANGUAGE_NOT_SPECIFIED, ); @@ -274,7 +274,7 @@ function path_taxonomy_term_insert(Term $term) { // Only save a non-empty alias. if (!empty($path['alias'])) { // Ensure fields for programmatic executions. - $path['source'] = 'taxonomy/term/' . $term->tid; + $path['source'] = 'taxonomy/term/' . $term->id(); $path['langcode'] = LANGUAGE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode']); } @@ -296,7 +296,7 @@ function path_taxonomy_term_update(Term $term) { if (!empty($path['alias'])) { $pid = (!empty($path['pid']) ? $path['pid'] : NULL); // Ensure fields for programmatic executions. - $path['source'] = 'taxonomy/term/' . $term->tid; + $path['source'] = 'taxonomy/term/' . $term->id(); $path['langcode'] = LANGUAGE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode'], $pid); } @@ -308,7 +308,7 @@ function path_taxonomy_term_update(Term $term) { */ function path_taxonomy_term_delete(Term $term) { // Delete all aliases associated with this term. - drupal_container()->get('path.crud')->delete(array('source' => 'taxonomy/term/' . $term->tid)); + drupal_container()->get('path.crud')->delete(array('source' => 'taxonomy/term/' . $term->id())); } /** diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php index 83e6ec9..4b26a04 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php @@ -35,13 +35,13 @@ public static function getInfo() { function testTaxonomyTermRdfaAttributes() { $vocabulary = $this->createVocabulary(); $term = $this->createTerm($vocabulary); - $term_uri = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE)); + $term_uri = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE)); // Parses the term's page and checks that the RDF output is correct. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = url('', array('absolute' => TRUE)); - $parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->tid), 'rdfa', $base_uri); + $parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri); // Inspects RDF graph output. // Term type. diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 547075a..a2f74a3 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -767,7 +767,7 @@ function rdf_preprocess_taxonomy_term(&$variables) { $term_label_meta = array( '#tag' => 'meta', '#attributes' => array( - 'about' => url('taxonomy/term/' . $term->tid), + 'about' => url('taxonomy/term/' . $term->id()), 'typeof' => $term->rdf_mapping['rdftype'], 'property' => $term->rdf_mapping['name']['predicates'], 'content' => $term->label(), diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 67f190e..8999156 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -373,7 +373,7 @@ public function testTaxonomyTermHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $term = taxonomy_term_load($term->tid); + $term = taxonomy_term_load($term->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type taxonomy_term', @@ -392,7 +392,7 @@ public function testTaxonomyTermHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - taxonomy_term_delete($term->tid); + taxonomy_term_delete($term->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_term_predelete called', diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php index 434311c..2c507fe 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php @@ -111,7 +111,7 @@ public function setUp() { $entity->name->value = $this->randomName(); $index = $i ? 1 : 0; $entity->user_id->target_id = $this->accounts[$index]->uid; - $entity->{$this->fieldName}->tid = $this->terms[$index]->tid; + $entity->{$this->fieldName}->id() = $this->terms[$index]->id(); $entity->save(); $this->entities[] = $entity; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index c5bfd17..358d834 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -323,16 +323,16 @@ function testBreadCrumbs() { $edit = array( 'parent[]' => array($parent_tid), ); - $this->drupalPost("taxonomy/term/{$term->tid}/edit", $edit, t('Save')); + $this->drupalPost("taxonomy/term/{$term->id()}/edit", $edit, t('Save')); } - $parent_tid = $term->tid; + $parent_tid = $term->id(); } $parent_mlid = 0; foreach ($tags as $name => $data) { $term = $data['term']; $edit = array( 'link_title' => "$name link", - 'link_path' => "taxonomy/term/{$term->tid}", + 'link_path' => "taxonomy/term/{$term->id()}", 'parent' => "$menu:{$parent_mlid}", ); $this->drupalPost("admin/structure/menu/manage/$menu/add", $edit, t('Save')); diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php index 1f0f2ee..703515a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -102,7 +102,7 @@ function setUp() { 'title' => $this->xss_label, 'type' => 'article', 'promote' => NODE_PROMOTED, - 'field_tags' => array(array('tid' => $this->term->tid)), + 'field_tags' => array(array('tid' => $this->term->id())), )); // Create a test comment on the test node. @@ -125,7 +125,7 @@ function testThemedEntity() { 'user', 'node', 'node/' . $this->node->nid, - 'taxonomy/term/' . $this->term->tid, + 'taxonomy/term/' . $this->term->id(), ); // Check each path in all available themes. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ac8bac3..a050c92 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1944,7 +1944,7 @@ function hook_mail($key, &$message, $params) { $variables += array( '%term_name' => $entity->name, '%term_description' => $entity->description, - '%term_id' => $entity->tid, + '%term_id' => $entity->id(), '%vocabulary_name' => $vocabulary->name, '%vocabulary_description' => $vocabulary->description, '%vocabulary_id' => $vocabulary->id(), diff --git a/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module b/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module index 2c6c00a..019b679 100644 --- a/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module +++ b/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module @@ -11,13 +11,25 @@ use Drupal\entity\Plugin\Core\Entity\EntityDisplay; /** + * Implements hook_entity_field_alter() + */ +function taxonomy_test_entity_field_info_alter(&$info, $entity_type) { + $info['definitions']['antonym'] = array( + 'label' => t('Antonym'), + 'description' => t('The term antonym.'), + 'type' => 'string_field', + 'computed' => TRUE, + ); +} + +/** * Implements hook_taxonomy_term_load(). */ function taxonomy_test_taxonomy_term_load(array $terms) { foreach ($terms as $term) { - $antonym = taxonomy_test_get_antonym($term->tid); + $antonym = taxonomy_test_get_antonym($term->id()); if ($antonym) { - $term->antonym = $antonym; + $term->antonym->value = $antonym; } } } @@ -26,11 +38,11 @@ function taxonomy_test_taxonomy_term_load(array $terms) { * Implements hook_taxonomy_term_insert(). */ function taxonomy_test_taxonomy_term_insert(Term $term) { - if (!empty($term->antonym)) { + if (!empty($term->antonym->value)) { db_insert('taxonomy_term_antonym') ->fields(array( - 'tid' => $term->tid, - 'name' => trim($term->antonym) + 'tid' => $term->id(), + 'name' => trim($term->antonym->value) )) ->execute(); } @@ -40,11 +52,11 @@ function taxonomy_test_taxonomy_term_insert(Term $term) { * Implements hook_taxonomy_term_update(). */ function taxonomy_test_taxonomy_term_update(Term $term) { - if (!empty($term->antonym)) { + if (!empty($term->antonym->value)) { db_merge('taxonomy_term_antonym') - ->key(array('tid' => $term->tid)) + ->key(array('tid' => $term->id())) ->fields(array( - 'name' => trim($term->antonym) + 'name' => trim($term->antonym->value) )) ->execute(); } @@ -55,7 +67,7 @@ function taxonomy_test_taxonomy_term_update(Term $term) { */ function taxonomy_test_taxonomy_term_delete(Term $term) { db_delete('taxonomy_term_antonym') - ->condition('tid', $term->tid) + ->condition('tid', $term->id()) ->execute(); } @@ -66,7 +78,7 @@ function taxonomy_test_taxonomy_term_view(Term $term, EntityDisplay $display, $v if ($view_mode == 'full') { $term->content['taxonomy_test_term_view_check'] = array( '#prefix' => '
', - '#markup' => t('The antonym is %antonym', array('%antonym' => $term->antonym)), + '#markup' => t('The antonym is %antonym', array('%antonym' => $term->antonym->value)), '#suffix' => '
', '#weight' => 10, ); @@ -80,7 +92,7 @@ function taxonomy_test_entity_view($entity, EntityDisplay $display, $view_mode, if ($entity->entityType() == 'taxonomy_term' && $view_mode == 'full') { $entity->content['taxonomy_test_entity_view_check'] = array( '#prefix' => '
', - '#markup' => t('The antonym is %antonym', array('%antonym' => $entity->antonym)), + '#markup' => t('The antonym is %antonym', array('%antonym' => $entity->antonym->value)), '#suffix' => '
', '#weight' => 20, ); @@ -92,7 +104,7 @@ function taxonomy_test_entity_view($entity, EntityDisplay $display, $view_mode, */ function taxonomy_test_form_taxonomy_term_form_alter(&$form, $form_state, $form_id) { $term = $form_state['controller']->getEntity($form_state); - $antonym = taxonomy_test_get_antonym($term->tid); + $antonym = taxonomy_test_get_antonym($term->id()); $form['advanced']['antonym'] = array( '#type' => 'textfield', '#title' => t('Antonym'), 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 bbb4638..40a3ac3 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 @@ -8,7 +8,7 @@ namespace Drupal\taxonomy\Plugin\Core\Entity; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\Entity; +use Drupal\Core\Entity\EntityNG; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -43,7 +43,7 @@ * permission_granularity = "bundle" * ) */ -class Term extends Entity implements ContentEntityInterface { +class Term extends EntityNG implements ContentEntityInterface { /** * The taxonomy term ID. @@ -95,7 +95,7 @@ class Term extends Entity implements ContentEntityInterface { * * @var integer */ - public $weight = 0; + public $weight; /** * The parent term(s) for this term. @@ -111,17 +111,31 @@ class Term extends Entity implements ContentEntityInterface { */ public $parent; + 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))), + ); + /** * Implements Drupal\Core\Entity\EntityInterface::id(). */ public function id() { - return $this->tid; + return $this->get('tid')->value; } /** - * Implements Drupal\Core\Entity\EntityInterface::bundle(). + * Overides \Drupal\Core\Entity\EntityNG::init(). */ - public function bundle() { - return $this->vid; + protected function init() { + parent::init(); + unset($this->tid); + unset($this->uuid); + unset($this->vid); + unset($this->name); + unset($this->weight); + unset($this->format); + unset($this->description); + unset($this->parent); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php index ab3d946..e49f31e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php @@ -67,7 +67,7 @@ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAI if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) { if ($terms = taxonomy_get_tree($vocabulary->id(), 0)) { foreach ($terms as $term) { - $options[$vocabulary->id()][$term->tid] = str_repeat('-', $term->depth) . check_plain($term->name); + $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . check_plain($term->name); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php index 3457126..9624d43 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php @@ -89,7 +89,7 @@ public function massageFormValues(array $values, array $form, array &$form_state // otherwise, create a new 'autocreate' term for insert/update. if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) { $term = array_pop($possibilities); - $item = array('tid' => $term->tid); + $item = array('tid' => $term->id()); } else { $vocabulary = reset($vocabularies); 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 9aefbec..4299de7 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->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->bundle(); - $this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($vocabularies[$term->bundle()]->label()); + $this->items[$term->node_nid][$term->id()]['name'] = check_plain($term->name); + $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()); if (!empty($this->options['link_to_taxonomy'])) { - $this->items[$term->node_nid][$term->tid]['make_link'] = TRUE; - $this->items[$term->node_nid][$term->tid]['path'] = 'taxonomy/term/' . $term->tid; + $this->items[$term->node_nid][$term->id()]['make_link'] = TRUE; + $this->items[$term->node_nid][$term->id()]['path'] = 'taxonomy/term/' . $term->id(); } } } 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 856254a..cc69b4f 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->tid => str_repeat('-', $term->depth) . $term->name); + $choice->option = array($term->id() => 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->tid] = $term->name; + $options[$term->id()] = $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->tid; + $tids[] = $term->id(); } 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->tid] = $term->name; + $this->value_options[$term->id()] = $term->name; } } return parent::adminSummary(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index 3735ad6..09cd392 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -8,12 +8,12 @@ namespace Drupal\taxonomy; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityFormControllerNG; /** * Base for controller for taxonomy term edit forms. */ -class TermFormController extends EntityFormController { +class TermFormController extends EntityFormControllerNG { /** * Overrides Drupal\Core\Entity\EntityFormController::form(). @@ -21,14 +21,14 @@ class TermFormController extends EntityFormController { public function form(array $form, array &$form_state, EntityInterface $term) { $vocabulary = taxonomy_vocabulary_load($term->bundle()); - $parent = array_keys(taxonomy_term_load_parents($term->tid)); + $parent = array_keys(taxonomy_term_load_parents($term->id())); $form_state['taxonomy']['parent'] = $parent; $form_state['taxonomy']['vocabulary'] = $vocabulary; $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), - '#default_value' => $term->name, + '#default_value' => $term->name->value, '#maxlength' => 255, '#required' => TRUE, '#weight' => -5, @@ -37,8 +37,8 @@ public function form(array $form, array &$form_state, EntityInterface $term) { $form['description'] = array( '#type' => 'text_format', '#title' => t('Description'), - '#default_value' => $term->description, - '#format' => $term->format, + '#default_value' => $term->description->value, + '#format' => $term->format->value, '#weight' => 0, ); $language_configuration = module_invoke('language', 'get_default_configuration', 'taxonomy_term', $vocabulary->id()); @@ -46,7 +46,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { '#type' => 'language_select', '#title' => t('Language'), '#languages' => LANGUAGE_ALL, - '#default_value' => $term->langcode, + '#default_value' => $term->language()->langcode, '#access' => !is_null($language_configuration['language_show']) && $language_configuration['language_show'], ); @@ -62,14 +62,14 @@ public function form(array $form, array &$form_state, EntityInterface $term) { // before loading the full vocabulary. Contrib modules can then intercept // before hook_form_alter to provide scalable alternatives. if (!config('taxonomy.settings')->get('override_selector')) { - $parent = array_keys(taxonomy_term_load_parents($term->tid)); - $children = taxonomy_get_tree($vocabulary->id(), $term->tid); + $parent = array_keys(taxonomy_term_load_parents($term->id())); + $children = taxonomy_get_tree($vocabulary->id(), $term->id()); // A term can't be the child of itself, nor of its children. foreach ($children as $child) { - $exclude[] = $child->tid; + $exclude[] = $child->id(); } - $exclude[] = $term->tid; + $exclude[] = $term->id(); $tree = taxonomy_get_tree($vocabulary->id()); $options = array('<' . t('root') . '>'); @@ -95,7 +95,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { '#type' => 'textfield', '#title' => t('Weight'), '#size' => 6, - '#default_value' => $term->weight, + '#default_value' => $term->weight->value, '#description' => t('Terms are displayed in ascending order by weight.'), '#required' => TRUE, ); @@ -107,10 +107,10 @@ public function form(array $form, array &$form_state, EntityInterface $term) { $form['tid'] = array( '#type' => 'value', - '#value' => $term->tid, + '#value' => $term->id(), ); - if (empty($term->tid)) { + if ($term->isNew()) { $form_state['redirect'] = current_path(); } @@ -136,12 +136,12 @@ public function submit(array $form, array &$form_state) { $term = parent::submit($form, $form_state); // Prevent leading and trailing spaces in term names. - $term->name = trim($term->name); + $term->name->value = trim($term->name->value); // Convert text_format field into values expected by taxonomy_term_save(). $description = $form_state['values']['description']; - $term->description = $description['value']; - $term->format = $description['format']; + $term->description->value = $description['value']; + $term->format->value = $description['format']; return $term; } @@ -156,11 +156,11 @@ public function save(array $form, array &$form_state) { switch ($status) { case SAVED_NEW: drupal_set_message(t('Created new term %term.', array('%term' => $term->label()))); - watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit')); + watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->id() . '/edit')); break; case SAVED_UPDATED: drupal_set_message(t('Updated term %term.', array('%term' => $term->label()))); - watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit')); + watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->id() . '/edit')); // Clear the page and block caches to avoid stale data. cache_invalidate_tags(array('content' => TRUE)); break; @@ -186,8 +186,8 @@ public function save(array $form, array &$form_state) { taxonomy_vocabulary_save($form_state['taxonomy']['vocabulary']); } - $form_state['values']['tid'] = $term->tid; - $form_state['tid'] = $term->tid; + $form_state['values']['tid'] = $term->id(); + $form_state['tid'] = $term->id(); } /** @@ -200,6 +200,6 @@ public function delete(array $form, array &$form_state) { unset($_GET['destination']); } $term = $this->getEntity($form_state); - $form_state['redirect'] = array('taxonomy/term/' . $term->tid . '/delete', array('query' => $destination)); + $form_state['redirect'] = array('taxonomy/term/' . $term->id() . '/delete', array('query' => $destination)); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermRenderController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermRenderController.php index ce8cb03..60728b4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermRenderController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermRenderController.php @@ -25,9 +25,9 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang foreach ($entities as $entity) { // Add the description if enabled. $display = $displays[$entity->bundle()]; - if (!empty($entity->description) && $display->getComponent('description')) { + if (!empty($entity->description->value) && $display->getComponent('description')) { $entity->content['description'] = array( - '#markup' => check_markup($entity->description, $entity->format, '', TRUE), + '#markup' => check_markup($entity->description->value, $entity->format->value, '', TRUE), '#prefix' => '
', '#suffix' => '
', ); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index d402c3a..73e2947 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -9,12 +9,12 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Query\QueryInterface; -use Drupal\Core\Entity\DatabaseStorageController; +use Drupal\Core\Entity\DatabaseStorageControllerNG; /** * Defines a Controller class for taxonomy terms. */ -class TermStorageController extends DatabaseStorageController { +class TermStorageController extends DatabaseStorageControllerNG { /** * Overrides Drupal\Core\Entity\DatabaseStorageController::create(). @@ -25,10 +25,6 @@ class TermStorageController extends DatabaseStorageController { */ public function create(array $values) { $entity = parent::create($values); - // Save new terms with no parents by default. - if (!isset($entity->parent)) { - $entity->parent = array(0); - } return $entity; } @@ -62,11 +58,11 @@ protected function postDelete($entities) { if ($children = taxonomy_term_load_children($tid)) { foreach ($children as $child) { // If the term has multiple parents, we don't delete it. - $parents = taxonomy_term_load_parents($child->tid); + $parents = taxonomy_term_load_parents($child->id()); // Because the parent has already been deleted, the parent count might // be 0. if (count($parents) <= 1) { - $orphans[] = $child->tid; + $orphans[] = $child->id(); } } } @@ -87,22 +83,20 @@ protected function postDelete($entities) { * Overrides Drupal\Core\Entity\DatabaseStorageController::postSave(). */ protected function postSave(EntityInterface $entity, $update) { - if (isset($entity->parent)) { - db_delete('taxonomy_term_hierarchy') - ->condition('tid', $entity->tid) - ->execute(); + 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->tid, - 'parent' => $parent - )); - } - $query->execute(); + foreach ($entity->parent as $parent) { + $query->values(array( + 'tid' => $entity->id(), + 'parent' => $parent->value, + )); } + $query->execute(); } /** @@ -118,4 +112,60 @@ public function resetCache(array $ids = NULL) { drupal_static_reset('taxonomy_term_load_children'); parent::resetCache($ids); } + + /** + * Overrides \Drupal\Core\Entity\DataBaseStorageControllerNG::basePropertyDefinitions(). + */ + public function baseFieldDefinitions() { + $properties['tid'] = array( + 'label' => t('Term ID'), + 'description' => t('The term ID.'), + 'type' => 'integer_field', + 'read-only' => TRUE, + ); + $properties['uuid'] = array( + 'label' => t('UUID'), + 'description' => t('The term UUID.'), + 'type' => 'string_field', + 'read-only' => TRUE, + ); + $properties['vid'] = array( + 'label' => t('Vocabulary ID'), + 'description' => t('The ID of the vocabulary to which the term is assigned.'), + 'type' => 'string_field', + ); + $properties['langcode'] = array( + 'label' => t('Language code'), + 'description' => t('The term language code.'), + 'type' => 'language_field', + ); + $properties['name'] = array( + 'label' => t('Name'), + 'description' => t('The term name.'), + 'type' => 'string_field', + ); + $properties['description'] = array( + 'label' => t('Description'), + 'description' => t('A description of the term'), + 'type' => 'string_field', + ); + // @todo: Combine with description. + $properties['format'] = array( + 'label' => t('Description format'), + 'description' => t('The filter format ID of the description.'), + 'type' => 'string_field', + ); + $properties['weight'] = array( + 'label' => t('Weight'), + 'description' => t('The weight of this term in relation to other terms.'), + 'type' => 'integer_field', + ); + $properties['parent'] = array( + 'label' => t('Term Parents'), + 'description' => t('The parents of this term.'), + 'type' => 'integer_field', + 'computed' => TRUE, + ); + return $properties; + } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php index 8ca1afd..e1534da 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php @@ -35,7 +35,7 @@ function testTaxonomyEfq() { $terms = array(); for ($i = 0; $i < 5; $i++) { $term = $this->createTerm($this->vocabulary); - $terms[$term->tid] = $term; + $terms[$term->id()] = $term; } $result = entity_query('taxonomy_term')->execute(); sort($result); @@ -47,14 +47,14 @@ function testTaxonomyEfq() { 'bundle' => $this->vocabulary->id(), ); $term = _field_create_entity_from_ids($ids); - $this->assertEqual($term->tid, $tid, 'Taxonomy term can be created based on the IDs'); + $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs'); // Create a second vocabulary and five more terms. $vocabulary2 = $this->createVocabulary(); $terms2 = array(); for ($i = 0; $i < 5; $i++) { $term = $this->createTerm($vocabulary2); - $terms2[$term->tid] = $term; + $terms2[$term->id()] = $term; } $result = entity_query('taxonomy_term') @@ -69,6 +69,6 @@ function testTaxonomyEfq() { 'bundle' => $vocabulary2->id(), ); $term = _field_create_entity_from_ids($ids); - $this->assertEqual($term->tid, $tid, 'Taxonomy term can be created based on the IDs'); + $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php index edddd1a..39cd8b1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php @@ -53,29 +53,29 @@ function testTaxonomyTermHooks() { $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->id() . '/add', $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name']); $term = reset($terms); - $this->assertEqual($term->antonym, $edit['antonym'], 'Antonym was loaded into the term object.'); + $this->assertEqual($term->antonym->value, $edit['antonym'], 'Antonym was loaded into the term object.'); // Update the term with a different antonym. $edit = array( 'name' => $this->randomName(), 'antonym' => 'Short', ); - $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); + $this->drupalPost('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save')); taxonomy_terms_static_reset(); - $term = taxonomy_term_load($term->tid); - $this->assertEqual($edit['antonym'], $term->antonym, 'Antonym was successfully edited.'); + $term = taxonomy_term_load($term->id()); + $this->assertEqual($edit['antonym'], $term->antonym->value, 'Antonym was successfully edited.'); // View the term and ensure that hook_taxonomy_term_view() and // hook_entity_view() are invoked. - $term = taxonomy_term_load($term->tid); + $term = taxonomy_term_load($term->id()); module_load_include('inc', 'taxonomy', 'taxonomy.pages'); $term_build = taxonomy_term_page($term); - $this->assertFalse(empty($term_build['taxonomy_terms'][$term->tid]['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.'); - $this->assertFalse(empty($term_build['taxonomy_terms'][$term->tid]['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.'); + $this->assertFalse(empty($term_build['taxonomy_terms'][$term->id()]['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.'); + $this->assertFalse(empty($term_build['taxonomy_terms'][$term->id()]['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.'); // Delete the term. - taxonomy_term_delete($term->tid); - $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField(); + taxonomy_term_delete($term->id()); + $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->id()))->fetchField(); $this->assertFalse($antonym, 'The antonym were deleted from the database.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php index d05f033..a2d74e2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php @@ -52,20 +52,20 @@ function testTaxonomyTermMultipleLoad() { // Remove one term from the array, then delete it. $deleted = array_shift($terms2); - taxonomy_term_delete($deleted->tid); - $deleted_term = taxonomy_term_load($deleted->tid); + taxonomy_term_delete($deleted->id()); + $deleted_term = taxonomy_term_load($deleted->id()); $this->assertFalse($deleted_term); // Load terms from the vocabulary by vid. $terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id())); $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.'); - $this->assertFalse(isset($terms3[$deleted->tid])); + $this->assertFalse(isset($terms3[$deleted->id()])); // Create a single term and load it by name. $term = $this->createTerm($vocabulary); - $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->name)); + $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->name->value)); $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.'); $loaded_term = reset($loaded_terms); - $this->assertEqual($term->tid, $loaded_term->tid, 'Term loaded by name successfully.'); + $this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index 3d28ec0..b1c5421 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -73,6 +73,7 @@ function setUp() { function testTaxonomyRss() { // Create two taxonomy terms. $term1 = $this->createTerm($this->vocabulary); + debug($term1->getPropertyValues()); // RSS display must be added manually. $this->drupalGet("admin/structure/types/manage/article/display"); @@ -92,22 +93,22 @@ function testTaxonomyRss() { $edit = array(); $langcode = LANGUAGE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); - $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid; + $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->id(); $this->drupalPost('node/add/article', $edit, t('Save')); // Check that the term is displayed when the RSS feed is viewed. $this->drupalGet('rss.xml'); $test_element = array( 'key' => 'category', - 'value' => $term1->name, + 'value' => $term1->name->value, 'attributes' => array( - 'domain' => url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE)), + 'domain' => url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE)), ), ); $this->assertRaw(format_xml_elements(array($test_element)), 'Term is displayed when viewing the rss feed.'); // Test that the feed page exists for the term. - $this->drupalGet("taxonomy/term/{$term1->tid}/feed"); + $this->drupalGet("taxonomy/term/{$term1->id()}/feed"); $this->assertRaw('term->id(); // Just being able to create the entity like this verifies a lot of code. $entity = entity_create('entity_test', array()); - $entity->field_test_taxonomy->tid = $this->term->tid; + $entity->field_test_taxonomy->tid = $this->term->id(); $entity->name->value = $this->randomName(); $entity->save(); $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->field_test_taxonomy instanceof FieldInterface, 'Field implements interface.'); $this->assertTrue($entity->field_test_taxonomy[0] instanceof FieldItemInterface, 'Field item implements interface.'); - $this->assertEqual($entity->field_test_taxonomy->tid, $this->term->tid); - $this->assertEqual($entity->field_test_taxonomy->entity->name, $this->term->name); + $this->assertEqual($entity->field_test_taxonomy->tid, $this->term->id()); + $this->assertEqual($entity->field_test_taxonomy->entity->name->value, $this->term->name->value); $this->assertEqual($entity->field_test_taxonomy->entity->id(), $tid); $this->assertEqual($entity->field_test_taxonomy->entity->uuid(), $this->term->uuid()); @@ -98,19 +98,19 @@ public function testTaxonomyTermReferenceItem() { $entity->field_test_taxonomy->entity->save(); // Verify it is the correct name. $term = entity_load('taxonomy_term', $tid); - $this->assertEqual($term->name, $new_name); + $this->assertEqual($term->name->value, $new_name); // Make sure the computed term reflects updates to the term id. $term2 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), - 'vid' => $this->term->vid, + 'vid' => $this->term->vid->value, 'langcode' => LANGUAGE_NOT_SPECIFIED, )); $term2->save(); - $entity->field_test_taxonomy->tid = $term2->tid; - $this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->tid); - $this->assertEqual($entity->field_test_taxonomy->entity->name, $term2->name); + $entity->field_test_taxonomy->tid = $term2->id(); + $this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id()); + $this->assertEqual($entity->field_test_taxonomy->entity->name->value, $term2->name->value); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 8c5571c..4f71f53 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -88,7 +88,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->drupalGet('test-entity/add/test_bundle'); $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is displayed'); $edit = array( - "{$this->field_name}[$langcode][]" => array($term1->tid, $term2->tid), + "{$this->field_name}[$langcode][]" => array($term1->id(), $term2->id()), ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -102,8 +102,8 @@ function testTaxonomyTermFieldMultipleVocabularies() { field_attach_prepare_view('test_entity', $entities, array($entity->bundle() => $display)); $entity->content = field_attach_view($entity, $display); $this->content = drupal_render($entity->content); - $this->assertText($term1->name, 'Term 1 name is displayed.'); - $this->assertText($term2->name, 'Term 2 name is displayed.'); + $this->assertText($term1->label(), 'Term 1 name is displayed.'); + $this->assertText($term2->label(), 'Term 2 name is displayed.'); // Delete vocabulary 2. taxonomy_vocabulary_delete($this->vocabulary2->id()); @@ -118,8 +118,8 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->content = drupal_render($entity->content); // Term 1 should still be displayed; term 2 should not be. - $this->assertText($term1->name, 'Term 1 name is displayed.'); - $this->assertNoText($term2->name, 'Term 2 name is not displayed.'); + $this->assertText($term1->label(), 'Term 1 name is displayed.'); + $this->assertNoText($term2->label(), 'Term 2 name is not displayed.'); // Verify that field and instance settings are correct. $field_info = field_info_field($this->field_name); @@ -131,7 +131,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { // Term 1 should still pass validation. $edit = array( - "{$this->field_name}[$langcode][]" => array($term1->tid), + "{$this->field_name}[$langcode][]" => array($term1->id()), ); $this->drupalPost(NULL, $edit, t('Save')); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index d5de5fa..363d326 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -78,7 +78,7 @@ function testTaxonomyTermFieldValidation() { $langcode = LANGUAGE_NOT_SPECIFIED; $entity = field_test_create_entity(); $term = $this->createTerm($this->vocabulary); - $entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid; + $entity->{$this->field_name}[$langcode][0]['tid'] = $term->id(); try { field_attach_validate($entity); $this->pass('Correct term does not cause validation error.'); @@ -89,7 +89,7 @@ function testTaxonomyTermFieldValidation() { $entity = field_test_create_entity(); $bad_term = $this->createTerm($this->createVocabulary()); - $entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->tid; + $entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->id(); try { field_attach_validate($entity); $this->fail('Wrong term causes validation error.'); @@ -113,7 +113,7 @@ function testTaxonomyTermFieldWidgets() { // Submit with some value. $edit = array( - "{$this->field_name}[$langcode]" => array($term->tid), + "{$this->field_name}[$langcode]" => array($term->id()), ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index f9cba0d..237f4b4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -104,47 +104,47 @@ function testTaxonomyIndex() { $langcode = LANGUAGE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); - $edit["{$this->field_name_1}[$langcode][]"] = $term_1->tid; - $edit["{$this->field_name_2}[$langcode][]"] = $term_1->tid; + $edit["{$this->field_name_1}[$langcode][]"] = $term_1->id(); + $edit["{$this->field_name_2}[$langcode][]"] = $term_1->id(); $this->drupalPost('node/add/article', $edit, t('Save')); // Check that the term is indexed, and only once. $node = $this->drupalGetNodeByTitle($edit["title"]); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 1 is indexed once.'); // Update the article to change one term. - $edit["{$this->field_name_1}[$langcode][]"] = $term_2->tid; + $edit["{$this->field_name_1}[$langcode][]"] = $term_2->id(); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Check that both terms are indexed. $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 1 is indexed.'); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_2->tid, + ':tid' => $term_2->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 2 is indexed.'); // Update the article to change another term. - $edit["{$this->field_name_2}[$langcode][]"] = $term_2->tid; + $edit["{$this->field_name_2}[$langcode][]"] = $term_2->id(); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Check that only one term is indexed. $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(0, $index_count, 'Term 1 is not indexed.'); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_2->tid, + ':tid' => $term_2->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); @@ -159,44 +159,44 @@ function testTaxonomyIndex() { // Check that the index was not changed. $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(0, $index_count, 'Term 1 is not indexed.'); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_2->tid, + ':tid' => $term_2->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); // Update the article to change one term. - $node->{$this->field_name_1}[$langcode] = array(array('tid' => $term_1->tid)); + $node->{$this->field_name_1}[$langcode] = array(array('tid' => $term_1->id())); $node->save(); // Check that both terms are indexed. $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 1 is indexed.'); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_2->tid, + ':tid' => $term_2->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 2 is indexed.'); // Update the article to change another term. - $node->{$this->field_name_2}[$langcode] = array(array('tid' => $term_1->tid)); + $node->{$this->field_name_2}[$langcode] = array(array('tid' => $term_1->id())); $node->save(); // Check that only one term is indexed. $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_1->tid, + ':tid' => $term_1->id(), ))->fetchField(); $this->assertEqual(1, $index_count, 'Term 1 is indexed once.'); $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array( ':nid' => $node->nid, - ':tid' => $term_2->tid, + ':tid' => $term_2->id(), ))->fetchField(); $this->assertEqual(0, $index_count, 'Term 2 is not indexed.'); } @@ -208,11 +208,11 @@ function testTaxonomyTermHierarchyBreadcrumbs() { // Create two taxonomy terms and set term2 as the parent of term1. $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); - $term1->parent = array($term2->tid); + $term1->parent = array($term2->id()); taxonomy_term_save($term1); // Verify that the page breadcrumbs include a link to the parent term. - $this->drupalGet('taxonomy/term/' . $term1->tid); - $this->assertRaw(l($term2->name, 'taxonomy/term/' . $term2->tid), 'Parent term link is displayed when viewing the node.'); + $this->drupalGet('taxonomy/term/' . $term1->id()); + $this->assertRaw(l($term2->label(), 'taxonomy/term/' . $term2->id()), 'Parent term link is displayed when viewing the node.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php index e2729dd..9bbc5a7 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php @@ -63,18 +63,18 @@ function testTermLanguage() { $this->drupalPost(NULL, $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name']); $term = reset($terms); - $this->assertEqual($term->langcode, $edit['langcode']); + $this->assertEqual($term->language()->langcode, $edit['langcode']); // Check if on the edit page the language is correct. - $this->drupalGet('taxonomy/term/' . $term->tid . '/edit'); + $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The term language was correctly selected.')); // Change the language of the term. $edit['langcode'] = 'bb'; - $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); + $this->drupalPost('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save')); // Check again that on the edit page the language is correct. - $this->drupalGet('taxonomy/term/' . $term->tid . '/edit'); + $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The term language was correctly selected.')); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 93cc8d4..1bf0051 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -71,27 +71,27 @@ function testTaxonomyTermHierarchy() { // Edit $term2, setting $term1 as parent. $edit = array(); - $edit['parent[]'] = array($term1->tid); - $this->drupalPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save')); + $edit['parent[]'] = array($term1->id()); + $this->drupalPost('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save')); // Check the hierarchy. - $children = taxonomy_term_load_children($term1->tid); - $parents = taxonomy_term_load_parents($term2->tid); - $this->assertTrue(isset($children[$term2->tid]), 'Child found correctly.'); - $this->assertTrue(isset($parents[$term1->tid]), 'Parent found correctly.'); + $children = taxonomy_term_load_children($term1->id()); + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.'); + $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.'); // Load and save a term, confirming that parents are still set. - $term = taxonomy_term_load($term2->tid); + $term = taxonomy_term_load($term2->id()); taxonomy_term_save($term); - $parents = taxonomy_term_load_parents($term2->tid); - $this->assertTrue(isset($parents[$term1->tid]), 'Parent found correctly.'); + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.'); // Create a third term and save this as a parent of term2. $term3 = $this->createTerm($this->vocabulary); - $term2->parent = array($term1->tid, $term3->tid); + $term2->parent = array($term1->id(), $term3->id()); taxonomy_term_save($term2); - $parents = taxonomy_term_load_parents($term2->tid); - $this->assertTrue(isset($parents[$term1->tid]) && isset($parents[$term3->tid]), 'Both parents found successfully.'); + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.'); } /** @@ -109,7 +109,7 @@ function testTaxonomyNode() { $langcode = LANGUAGE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); - $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid; + $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->id(); $this->drupalPost('node/add/article', $edit, t('Save')); // Check that the term is displayed when the node is viewed. @@ -123,7 +123,7 @@ function testTaxonomyNode() { $this->assertText($term1->name, 'Term is displayed after saving the node with no changes.'); // Edit the node with a different term. - $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term2->tid; + $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term2->id(); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $this->drupalGet('node/' . $node->nid); @@ -194,11 +194,11 @@ function testNodeTermCreationAndDeletion() { } // Delete term 1 from the term edit page. - $this->drupalPost('taxonomy/term/' . $term_objects['term1']->tid . '/edit', array(), t('Delete')); + $this->drupalPost('taxonomy/term/' . $term_objects['term1']->id() . '/edit', array(), t('Delete')); $this->drupalPost(NULL, NULL, t('Delete')); // Delete term 2 from the term delete page. - $this->drupalPost('taxonomy/term/' . $term_objects['term2']->tid . '/delete', array(), t('Delete')); + $this->drupalPost('taxonomy/term/' . $term_objects['term2']->id() . '/delete', array(), t('Delete')); $term_names = array($term_objects['term3']->name, $term_objects['term4']->name); // Get the node. @@ -316,7 +316,7 @@ function testTermInterface() { ); // Edit the term. - $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); + $this->drupalPost('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save')); // Check that the term is still present at admin UI after edit. $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->id()); @@ -324,7 +324,7 @@ function testTermInterface() { $this->assertLink(t('edit')); // View the term and check that it is correct. - $this->drupalGet('taxonomy/term/' . $term->tid); + $this->drupalGet('taxonomy/term/' . $term->id()); $this->assertText($edit['name'], 'The randomly generated term name is present.'); $this->assertText($edit['description[value]'], 'The randomly generated term description is present.'); @@ -333,22 +333,22 @@ function testTermInterface() { // Check that it does NOT show a description when description is blank. $term->description = ''; taxonomy_term_save($term); - $this->drupalGet('taxonomy/term/' . $term->tid); + $this->drupalGet('taxonomy/term/' . $term->id()); $this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.'); // Check that the term feed page is working. - $this->drupalGet('taxonomy/term/' . $term->tid . '/feed'); + $this->drupalGet('taxonomy/term/' . $term->id() . '/feed'); // Check that the term edit page does not try to interpret additional path // components as arguments for taxonomy_term_form(). - $this->drupalGet('taxonomy/term/' . $term->tid . '/edit/' . $this->randomName()); + $this->drupalGet('taxonomy/term/' . $term->id() . '/edit/' . $this->randomName()); // Delete the term. - $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', array(), t('Delete')); + $this->drupalPost('taxonomy/term/' . $term->id() . '/edit', array(), t('Delete')); $this->drupalPost(NULL, NULL, t('Delete')); // Assert that the term no longer exists. - $this->drupalGet('taxonomy/term/' . $term->tid); + $this->drupalGet('taxonomy/term/' . $term->id()); $this->assertResponse(404, 'The taxonomy term page was not found.'); } @@ -374,18 +374,18 @@ function testTermReorder() { // term3, term1 by setting weight property, make term3 a child of term2 by // setting the parent and depth properties, and update all hidden fields. $edit = array( - 'tid:' . $term2->tid . ':0[tid]' => $term2->tid, - 'tid:' . $term2->tid . ':0[parent]' => 0, - 'tid:' . $term2->tid . ':0[depth]' => 0, - 'tid:' . $term2->tid . ':0[weight]' => 0, - 'tid:' . $term3->tid . ':0[tid]' => $term3->tid, - 'tid:' . $term3->tid . ':0[parent]' => $term2->tid, - 'tid:' . $term3->tid . ':0[depth]' => 1, - 'tid:' . $term3->tid . ':0[weight]' => 1, - 'tid:' . $term1->tid . ':0[tid]' => $term1->tid, - 'tid:' . $term1->tid . ':0[parent]' => 0, - 'tid:' . $term1->tid . ':0[depth]' => 0, - 'tid:' . $term1->tid . ':0[weight]' => 2, + 'tid:' . $term2->id() . ':0[tid]' => $term2->id(), + 'tid:' . $term2->id() . ':0[parent]' => 0, + 'tid:' . $term2->id() . ':0[depth]' => 0, + 'tid:' . $term2->id() . ':0[weight]' => 0, + 'tid:' . $term3->id() . ':0[tid]' => $term3->id(), + 'tid:' . $term3->id() . ':0[parent]' => $term2->id(), + 'tid:' . $term3->id() . ':0[depth]' => 1, + 'tid:' . $term3->id() . ':0[weight]' => 1, + 'tid:' . $term1->id() . ':0[tid]' => $term1->id(), + 'tid:' . $term1->id() . ':0[parent]' => 0, + 'tid:' . $term1->id() . ':0[depth]' => 0, + 'tid:' . $term1->id() . ':0[weight]' => 2, ); $this->drupalPost(NULL, $edit, t('Save')); @@ -393,9 +393,9 @@ function testTermReorder() { drupal_static_reset('taxonomy_get_treeparent'); drupal_static_reset('taxonomy_get_treeterms'); $terms = taxonomy_get_tree($this->vocabulary->id()); - $this->assertEqual($terms[0]->tid, $term2->tid, 'Term 2 was moved above term 1.'); - $this->assertEqual($terms[1]->parents, array($term2->tid), 'Term 3 was made a child of term 2.'); - $this->assertEqual($terms[2]->tid, $term1->tid, 'Term 1 was moved below term 2.'); + $this->assertEqual($terms[0]->id(), $term2->id(), 'Term 2 was moved above term 1.'); + $this->assertEqual($terms[1]->parents, array($term2->id()), 'Term 3 was made a child of term 2.'); + $this->assertEqual($terms[2]->id(), $term1->id(), 'Term 1 was moved below term 2.'); $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id(), array(), t('Reset to alphabetical')); // Submit confirmation form. @@ -405,10 +405,10 @@ function testTermReorder() { drupal_static_reset('taxonomy_get_treeparent'); drupal_static_reset('taxonomy_get_treeterms'); $terms = taxonomy_get_tree($this->vocabulary->id()); - $this->assertEqual($terms[0]->tid, $term1->tid, 'Term 1 was moved to back above term 2.'); - $this->assertEqual($terms[1]->tid, $term2->tid, 'Term 2 was moved to back below term 1.'); - $this->assertEqual($terms[2]->tid, $term3->tid, 'Term 3 is still below term 2.'); - $this->assertEqual($terms[2]->parents, array($term2->tid), 'Term 3 is still a child of term 2.' . var_export($terms[1]->tid, 1)); + $this->assertEqual($terms[0]->id(), $term1->id(), 'Term 1 was moved to back above term 2.'); + $this->assertEqual($terms[1]->id(), $term2->id(), 'Term 2 was moved to back below term 1.'); + $this->assertEqual($terms[2]->id(), $term3->id(), 'Term 3 is still below term 2.'); + $this->assertEqual($terms[2]->parents, array($term2->id()), 'Term 3 is still a child of term 2.' . var_export($terms[1]->id(), 1)); } /** @@ -422,7 +422,7 @@ function testTermMultipleParentsInterface() { $edit = array( 'name' => $this->randomName(12), 'description[value]' => $this->randomName(100), - 'parent[]' => array(0, $parent->tid), + 'parent[]' => array(0, $parent->id()), ); // Save the new term. $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id() . '/add', $edit, t('Save')); @@ -435,9 +435,9 @@ function testTermMultipleParentsInterface() { $this->assertEqual($edit['description[value]'], $term->description, 'Term description was successfully saved.'); // Check that the parent tid is still there. The other parent () is // not added by taxonomy_term_load_parents(). - $parents = taxonomy_term_load_parents($term->tid); + $parents = taxonomy_term_load_parents($term->id()); $parent = reset($parents); - $this->assertEqual($edit['parent[]'][1], $parent->tid, 'Term parents were successfully saved.'); + $this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.'); } /** @@ -448,19 +448,19 @@ function testTaxonomyGetTermByName() { // Load the term with the exact name. $terms = taxonomy_term_load_multiple_by_name($term->name); - $this->assertTrue(isset($terms[$term->tid]), 'Term loaded using exact name.'); + $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name.'); // Load the term with space concatenated. $terms = taxonomy_term_load_multiple_by_name(' ' . $term->name . ' '); - $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with extra whitespace.'); + $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with extra whitespace.'); // Load the term with name uppercased. $terms = taxonomy_term_load_multiple_by_name(strtoupper($term->name)); - $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with uppercased name.'); + $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with uppercased name.'); // Load the term with name lowercased. $terms = taxonomy_term_load_multiple_by_name(strtolower($term->name)); - $this->assertTrue(isset($terms[$term->tid]), 'Term loaded with lowercased name.'); + $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with lowercased name.'); // Try to load an invalid term name. $terms = taxonomy_term_load_multiple_by_name('Banana'); @@ -485,7 +485,7 @@ function testTaxonomyGetTermByName() { // Load single term when restricted to one vocabulary. $terms = taxonomy_term_load_multiple_by_name($term->name, $this->vocabulary->id()); $this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.'); - $this->assertTrue(isset($terms[$term->tid]), 'Term loaded using exact name and vocabulary machine name.'); + $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name and vocabulary machine name.'); // Create a new term with another name. $term2 = $this->createTerm($this->vocabulary); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php index 8656505..166ab86 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php @@ -24,7 +24,7 @@ function testTermDelete() { $vocabulary = $this->createVocabulary(); $valid_term = $this->createTerm($vocabulary); // Delete a valid term. - taxonomy_term_delete($valid_term->tid); + taxonomy_term_delete($valid_term->id()); $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id())); $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion'); @@ -44,13 +44,13 @@ function testTaxonomyVocabularyTree() { } // $term[2] is a child of 1 and 5. - $term[2]->parent = array($term[1]->tid, $term[5]->tid); + $term[2]->parent = array($term[1]->id(), $term[5]->id()); taxonomy_term_save($term[2]); // $term[3] is a child of 2. - $term[3]->parent = array($term[2]->tid); + $term[3]->parent = array($term[2]->id()); taxonomy_term_save($term[3]); // $term[5] is a child of 4. - $term[5]->parent = array($term[4]->tid); + $term[5]->parent = array($term[4]->id()); taxonomy_term_save($term[5]); /** @@ -65,7 +65,7 @@ function testTaxonomyVocabularyTree() { * ------ term[3] | depth: 3 */ // Count $term[1] parents with $max_depth = 1. - $tree = taxonomy_get_tree($vocabulary->id(), $term[1]->tid, 1); + $tree = taxonomy_get_tree($vocabulary->id(), $term[1]->id(), 1); $this->assertEqual(1, count($tree), 'We have one parent with depth 1.'); // Count all vocabulary tree elements. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php index c14a562..62e18c6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php @@ -49,11 +49,11 @@ function testTaxonomyTermThemes() { // Viewing a taxonomy term should use the default theme. $term = $this->createTerm($vocabulary); - $this->drupalGet('taxonomy/term/' . $term->tid); + $this->drupalGet('taxonomy/term/' . $term->id()); $this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page for viewing a taxonomy term.")); // Editing a taxonomy term should use the same theme as adding one. - $this->drupalGet('taxonomy/term/' . $term->tid . '/edit'); + $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page for editing a taxonomy term.")); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index ea73152..daaeb91 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -71,21 +71,21 @@ function testTaxonomyTokenReplacement() { // Edit $term2, setting $term1 as parent. $edit = array(); $edit['name'] = 'Blinking Text'; - $edit['parent[]'] = array($term1->tid); - $this->drupalPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save')); + $edit['parent[]'] = array($term1->id()); + $this->drupalPost('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save')); // Create node with term2. $edit = array(); $node = $this->drupalCreateNode(array('type' => 'article')); - $edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->tid; + $edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->id(); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Generate and test sanitized tokens for term1. $tests = array(); - $tests['[term:tid]'] = $term1->tid; - $tests['[term:name]'] = check_plain($term1->name); - $tests['[term:description]'] = check_markup($term1->description, $term1->format); - $tests['[term:url]'] = url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE)); + $tests['[term:tid]'] = $term1->id(); + $tests['[term:name]'] = check_plain($term1->name->value); + $tests['[term:description]'] = check_markup($term1->description->value, $term1->format->value); + $tests['[term:url]'] = url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE)); $tests['[term:node-count]'] = 0; $tests['[term:parent:name]'] = '[term:parent:name]'; $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name); @@ -97,13 +97,13 @@ function testTaxonomyTokenReplacement() { // Generate and test sanitized tokens for term2. $tests = array(); - $tests['[term:tid]'] = $term2->tid; - $tests['[term:name]'] = check_plain($term2->name); - $tests['[term:description]'] = check_markup($term2->description, $term2->format); - $tests['[term:url]'] = url('taxonomy/term/' . $term2->tid, array('absolute' => TRUE)); + $tests['[term:tid]'] = $term2->id(); + $tests['[term:name]'] = check_plain($term2->name->value); + $tests['[term:description]'] = check_markup($term2->description->value, $term2->format->value); + $tests['[term:url]'] = url('taxonomy/term/' . $term2->id(), array('absolute' => TRUE)); $tests['[term:node-count]'] = 1; - $tests['[term:parent:name]'] = check_plain($term1->name); - $tests['[term:parent:url]'] = url('taxonomy/term/' . $term1->tid, array('absolute' => TRUE)); + $tests['[term:parent:name]'] = check_plain($term1->name->value); + $tests['[term:parent:url]'] = url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE)); $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]'; $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipNodeTermDataTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipNodeTermDataTest.php index 0dbe0c2..dfb3af4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipNodeTermDataTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipNodeTermDataTest.php @@ -29,7 +29,7 @@ public static function getInfo() { function testViewsHandlerRelationshipNodeTermData() { $view = views_get_view('test_taxonomy_node_term_data'); - $this->executeView($view, array($this->term1->tid, $this->term2->tid)); + $this->executeView($view, array($this->term1->id(), $this->term2->id())); $resultset = array( array( 'nid' => $this->nodes[0]->nid, diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php index dbe4b3e..c87a437 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php @@ -37,11 +37,11 @@ public function testRelationship() { $expected_result = array( array( 'nid' => $this->nodes[1]->nid, - 'tid' => $this->term2->tid, + 'tid' => $this->term2->id(), ), array( 'nid' => $this->nodes[1]->nid, - 'tid' => $this->term1->tid, + 'tid' => $this->term1->id(), ), ); $this->assertIdenticalResultset($view, $expected_result, $map); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php index 5f98990..6de1b17 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php @@ -54,8 +54,8 @@ function setUp() { $node = array(); $node['type'] = 'article'; - $node['field_views_testing_tags'][]['tid'] = $this->term1->tid; - $node['field_views_testing_tags'][]['tid'] = $this->term2->tid; + $node['field_views_testing_tags'][]['tid'] = $this->term1->id(); + $node['field_views_testing_tags'][]['tid'] = $this->term2->id(); $this->nodes[] = $this->drupalCreateNode($node); $this->nodes[] = $this->drupalCreateNode($node); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index d73302b..d77b212 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -55,9 +55,9 @@ function testTaxonomyVocabularyDeleteWithTerms() { } // Set up hierarchy. term 2 is a child of 1 and 4 a child of 1 and 2. - $terms[2]->parent = array($terms[1]->tid); + $terms[2]->parent = array($terms[1]->id()); taxonomy_term_save($terms[2]); - $terms[4]->parent = array($terms[1]->tid, $terms[2]->tid); + $terms[4]->parent = array($terms[1]->id(), $terms[2]->id()); taxonomy_term_save($terms[4]); // Assert that there are now 5 terms. diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 6305e48..c74a5ff 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -215,12 +215,12 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { // Finally, if we've gotten down this far, we're rendering a term on this page. $page_entries++; - $term_deltas[$term->tid] = isset($term_deltas[$term->tid]) ? $term_deltas[$term->tid] + 1 : 0; - $key = 'tid:' . $term->tid . ':' . $term_deltas[$term->tid]; + $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->tid; + $form['#first_tid'] = $term->id(); } // Keep a variable to make sure at least 2 root elements are displayed. if ($term->parents[0] == 0) { @@ -260,12 +260,12 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { unset($form[$key]['#term']['parents'], $term->parents); } - $form[$key]['view'] = array('#type' => 'link', '#title' => $term->label(), '#href' => "taxonomy/term/$term->tid"); + $form[$key]['view'] = array('#type' => 'link', '#title' => $term->label(), '#href' => "taxonomy/term/$term->id()"); if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $form['#parent_fields'] = TRUE; $form[$key]['tid'] = array( '#type' => 'hidden', - '#value' => $term->tid + '#value' => $term->id() ); $form[$key]['parent'] = array( '#type' => 'hidden', @@ -286,13 +286,13 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { ); } $operations = array( - 'edit' => array('title' => t('edit'), 'href' => 'taxonomy/term/' . $term->tid . '/edit', 'query' => $destination), - 'delete' => array('title' => t('delete'), 'href' => 'taxonomy/term/' . $term->tid . '/delete', 'query' => $destination), + 'edit' => array('title' => t('edit'), 'href' => 'taxonomy/term/' . $term->id() . '/edit', 'query' => $destination), + 'delete' => array('title' => t('delete'), 'href' => 'taxonomy/term/' . $term->id() . '/delete', 'query' => $destination), ); if (module_invoke('translation_entity', 'translate_access', $term)) { $operations['translate'] = array( 'title' => t('translate'), - 'href' => 'taxonomy/term/' . $term->tid . '/translations', + 'href' => 'taxonomy/term/' . $term->id() . '/translations', 'query' => $destination, ); } @@ -427,12 +427,12 @@ function taxonomy_overview_terms_submit($form, &$form_state) { // fully populated term object to save. db_update('taxonomy_term_hierarchy') ->fields(array('parent' => $term->parent)) - ->condition('tid', $term->tid, '=') + ->condition('tid', $term->id(), '=') ->execute(); db_update('taxonomy_term_data') ->fields(array('weight' => $term->weight)) - ->condition('tid', $term->tid, '=') + ->condition('tid', $term->id(), '=') ->execute(); } @@ -555,7 +555,7 @@ function taxonomy_term_add($vocabulary) { */ function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { // Always provide entity id in the same form key as in the entity edit form. - $form['tid'] = array('#type' => 'value', '#value' => $term->tid); + $form['tid'] = array('#type' => 'value', '#value' => $term->id()); $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->bundle());; $form['type'] = array('#type' => 'value', '#value' => 'term'); diff --git a/core/modules/taxonomy/taxonomy.api.php b/core/modules/taxonomy/taxonomy.api.php index d2f41f6..de08052 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -158,7 +158,7 @@ function hook_taxonomy_term_create(\Drupal\taxonomy\Plugin\Core\Entity\Term $ter function hook_taxonomy_term_load(array $terms) { $result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms))); foreach ($result as $record) { - $terms[$record->tid]->foo = $record->foo; + $terms[$record->id()]->foo = $record->foo; } } @@ -190,7 +190,7 @@ function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) { if ($synonym) { db_insert('taxonomy_term_synonym') ->fields(array( - 'tid' => $term->tid, + 'tid' => $term->id(), 'name' => rtrim($synonym), )) ->execute(); @@ -214,7 +214,7 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { if ($synonym) { db_insert('taxonomy_term_synonym') ->fields(array( - 'tid' => $term->tid, + 'tid' => $term->id(), 'name' => rtrim($synonym), )) ->execute(); @@ -236,7 +236,7 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { * @see taxonomy_term_delete() */ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { - db_delete('term_synoynm')->condition('tid', $term->tid)->execute(); + db_delete('term_synoynm')->condition('tid', $term->id())->execute(); } /** @@ -251,7 +251,7 @@ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { * @see taxonomy_term_delete() */ function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { - db_delete('term_synoynm')->condition('tid', $term->tid)->execute(); + db_delete('term_synoynm')->condition('tid', $term->id())->execute(); } /** diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 43d2ac8..47030b9 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -142,7 +142,7 @@ function taxonomy_entity_bundle_info() { */ function taxonomy_term_uri($term) { return array( - 'path' => 'taxonomy/term/' . $term->tid, + 'path' => 'taxonomy/term/' . $term->id(), ); } @@ -359,8 +359,8 @@ function taxonomy_menu() { 'title' => 'Add term', 'page callback' => 'taxonomy_term_add', 'page arguments' => array(3), - 'access callback' => 'entity_page_create_access', - 'access arguments' => array('taxonomy_term'), + 'access callback' => 'taxonomy_term_create_access', + 'access arguments' => array(3), 'type' => MENU_LOCAL_ACTION, 'file' => 'taxonomy.admin.inc', ); @@ -369,6 +369,19 @@ function taxonomy_menu() { } /** + * Access callback for creating a new taxonomy term. + * + * @param \Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary + * The vocabulary entity that represents the term bundle. + * + * @return bool + * TRUE if access is allowed, FALSE if not. + */ +function taxonomy_term_create_access(Vocabulary $vocabulary) { + return entity_page_create_access('taxonomy_term', $vocabulary->id()); +} + +/** * Implements hook_admin_paths(). */ function taxonomy_admin_paths() { @@ -436,7 +449,7 @@ function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_te $hierarchy = TAXONOMY_HIERARCHY_DISABLED; foreach ($tree as $term) { // Update the changed term with the new parent value before comparison. - if ($term->tid == $changed_term['tid']) { + if ($term->id() == $changed_term['tid']) { $term = (object) $changed_term; $term->parents = $term->parent; } @@ -465,7 +478,7 @@ function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_te * * @return * Status constant indicating whether term was inserted (SAVED_NEW) or updated - * (SAVED_UPDATED). When inserting a new term, $term->tid will contain the + * (SAVED_UPDATED). When inserting a new term, $term->id() will contain the * term ID of the newly created term. */ function taxonomy_term_save(Term $term) { @@ -558,7 +571,7 @@ function template_preprocess_taxonomy_term(&$variables) { $variables['attributes']['class'][] = 'vocabulary-' . $vocabulary_name_css; $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->bundle(); - $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->tid; + $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->id(); } /** @@ -569,7 +582,7 @@ function template_preprocess_taxonomy_term(&$variables) { */ function taxonomy_term_is_page(Term $term) { $page_term = menu_get_object('taxonomy_term', 2); - return (!empty($page_term) ? $page_term->tid == $term->tid : FALSE); + return (!empty($page_term) ? $page_term->id() == $term->id() : FALSE); } /** @@ -652,7 +665,7 @@ function taxonomy_term_load_parents_all($tid) { if ($term = taxonomy_term_load($tid)) { $parents[] = $term; $n = 0; - while ($parent = taxonomy_term_load_parents($parents[$n]->tid)) { + while ($parent = taxonomy_term_load_parents($parents[$n]->id())) { $parents = array_merge($parents, $parent); $n++; } @@ -776,26 +789,26 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities break; } $term = $load_entities ? $term_entities[$child] : $terms[$vid][$child]; - if (isset($parents[$vid][$term->tid])) { + if (isset($parents[$vid][$load_entities ? $term->id() : $term->tid])) { // Clone the term so that the depth attribute remains correct // in the event of multiple parents. $term = clone $term; } $term->depth = $depth; unset($term->parent); - $term->parents = $parents[$vid][$term->tid]; + $term->parents = $parents[$vid][$load_entities ? $term->id() : $term->tid]; $tree[] = $term; - if (!empty($children[$vid][$term->tid])) { + if (!empty($children[$vid][$load_entities ? $term->id() : $term->tid])) { $has_children = TRUE; // We have to continue with this parent later. $process_parents[] = $parent; // Use the current term as parent for the next iteration. - $process_parents[] = $term->tid; + $process_parents[] = $term->id(); // Reset pointers for child lists because we step in there more often // with multi parents. - reset($children[$vid][$term->tid]); + reset($children[$vid][$term->id()]); // Move pointer so that we get the correct term the next time. next($children[$vid][$parent]); break; @@ -929,7 +942,7 @@ function taxonomy_term_load($tid) { * Helper function for array_map purposes. */ function _taxonomy_get_tid_from_term(Term $term) { - return $term->tid; + return $term->id(); } /** @@ -1045,7 +1058,7 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan elseif (!empty($settings['parent'])) { $ancestors = taxonomy_term_load_parents_all($item['tid']); foreach ($ancestors as $ancestor) { - if ($ancestor->tid == $settings['parent']) { + if ($ancestor->id() == $settings['parent']) { $validate = TRUE; break 2; } @@ -1167,7 +1180,7 @@ function taxonomy_allowed_values($field, $instance, EntityInterface $entity) { if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) { if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) { foreach ($terms as $term) { - $options[$term->tid] = str_repeat('-', $term->depth) . $term->label(); + $options[$term->id()] = str_repeat('-', $term->depth) . $term->label(); } } } @@ -1357,7 +1370,7 @@ function taxonomy_field_presave(EntityInterface $entity, $field, $instance, $lan if (!$item['tid'] && isset($item['entity'])) { unset($item['tid']); taxonomy_term_save($item['entity']); - $items[$delta]['tid'] = $item['entity']->tid; + $items[$delta]['tid'] = $item['entity']->id(); } } } @@ -1474,7 +1487,7 @@ function taxonomy_delete_node_index(EntityInterface $node) { function taxonomy_taxonomy_term_delete(Term $term) { if (config('taxonomy.settings')->get('maintain_index_table')) { // Clean up the {taxonomy_index} table when terms are deleted. - db_delete('taxonomy_index')->condition('tid', $term->tid)->execute(); + db_delete('taxonomy_index')->condition('tid', $term->id())->execute(); } } diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index b6f1329..31146f7 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -19,21 +19,17 @@ function taxonomy_term_page(Term $term) { // Assign the term name as the page title. drupal_set_title($term->label()); - // Build breadcrumb based on the hierarchy of the term. - $current = (object) array( - 'tid' => $term->tid, - ); // @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($current->tid)) { - $current = array_shift($parents); - $breadcrumb[] = l($current->label(), 'taxonomy/term/' . $current->tid); + while ($parents = taxonomy_term_load_parents($term->id())) { + $term = array_shift($parents); + $breadcrumb[] = l($term->label(), 'taxonomy/term/' . $term->id()); } $breadcrumb[] = l(t('Home'), NULL); $breadcrumb = array_reverse($breadcrumb); drupal_set_breadcrumb($breadcrumb); - drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->label()); + drupal_add_feed('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->label()); $uri = $term->uri(); @@ -43,7 +39,7 @@ function taxonomy_term_page(Term $term) { drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE); $build['taxonomy_terms'] = taxonomy_term_view_multiple(array($term->id() => $term)); - if ($nids = taxonomy_select_nodes($term->tid, TRUE, config('node.settings')->get('items_per_page'))) { + if ($nids = taxonomy_select_nodes($term->id(), TRUE, config('node.settings')->get('items_per_page'))) { $nodes = node_load_multiple($nids); $build['nodes'] = node_view_multiple($nodes); $build['pager'] = array( @@ -68,12 +64,12 @@ function taxonomy_term_page(Term $term) { * The taxonomy term entity. */ function taxonomy_term_feed(Term $term) { - $channel['link'] = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE)); + $channel['link'] = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE)); $channel['title'] = config('system.site')->get('name') . ' - ' . $term->label(); // Only display the description if we have a single term, to avoid clutter and confusion. // HTML will be removed from feed description. - $channel['description'] = check_markup($term->description, $term->format, '', TRUE); - $nids = taxonomy_select_nodes($term->tid, FALSE, config('system.rss')->get('items.limit')); + $channel['description'] = check_markup($term->description->value, $term->format->value, '', TRUE); + $nids = taxonomy_select_nodes($term->id(), FALSE, config('system.rss')->get('items.limit')); return node_feed($nids, $channel); } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index 34099ce..900ba1a 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -98,7 +98,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = foreach ($tokens as $name => $original) { switch ($name) { case 'tid': - $replacements[$original] = $term->tid; + $replacements[$original] = $term->id(); break; case 'name': @@ -116,7 +116,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = case 'node-count': $query = db_select('taxonomy_index'); - $query->condition('tid', $term->tid); + $query->condition('tid', $term->id()); $query->addTag('term_node_count'); $count = $query->countQuery()->execute()->fetchField(); $replacements[$original] = $count; @@ -128,7 +128,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'parent': - if ($parents = taxonomy_term_load_parents($term->tid)) { + if ($parents = taxonomy_term_load_parents($term->id())) { $parent = array_pop($parents); $replacements[$original] = check_plain($parent->name); } @@ -141,7 +141,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $replacements += token_generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); } - if (($vocabulary_tokens = token_find_with_prefix($tokens, 'parent')) && $parents = taxonomy_term_load_parents($term->tid)) { + if (($vocabulary_tokens = token_find_with_prefix($tokens, 'parent')) && $parents = taxonomy_term_load_parents($term->id())) { $parent = array_pop($parents); $replacements += token_generate('term', $vocabulary_tokens, array('term' => $parent), $options); } diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index 0644f82..1e62754 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -411,7 +411,7 @@ function views_taxonomy_set_breadcrumb(&$breadcrumb, &$argument) { $parents = taxonomy_get_parents_all($argument->argument); foreach (array_reverse($parents) as $parent) { // Unfortunately parents includes the current argument. Skip. - if ($parent->tid == $argument->argument) { + if ($parent->id() == $argument->argument) { continue; } if (!empty($argument->options['use_taxonomy_term_path'])) { @@ -419,7 +419,7 @@ function views_taxonomy_set_breadcrumb(&$breadcrumb, &$argument) { $path = $path['path']; } else { - $args[$argument->position] = $parent->tid; + $args[$argument->position] = $parent->id(); $path = $argument->view->getUrl($args); } $breadcrumb[$path] = check_plain($parent->name); diff --git a/core/modules/taxonomy/templates/taxonomy-term.tpl.php b/core/modules/taxonomy/templates/taxonomy-term.tpl.php index 712e83c..e666236 100644 --- a/core/modules/taxonomy/templates/taxonomy-term.tpl.php +++ b/core/modules/taxonomy/templates/taxonomy-term.tpl.php @@ -37,7 +37,7 @@ * @ingroup themeable */ ?> -
> +
>

diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index c4f90b8..126e62d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -96,7 +96,7 @@ protected function setUp() { $term = $this->createTerm($this->vocabulary); $values = array('created' => $time, 'type' => 'page'); - $values[$this->field_name][]['tid'] = $term->tid; + $values[$this->field_name][]['tid'] = $term->id(); // Make every other node promoted. if ($i % 2) { diff --git a/core/modules/views/views_ui/admin.inc b/core/modules/views/views_ui/admin.inc index abf75b0..a2ab910 100644 --- a/core/modules/views/views_ui/admin.inc +++ b/core/modules/views/views_ui/admin.inc @@ -237,7 +237,7 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { foreach ($typed_terms as $typed_term) { if ($terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($typed_term), 'vid' => array_keys($vocabularies)))) { $term = array_pop($terms); - $value['tids'][] = $term->tid; + $value['tids'][] = $term->id(); } } // Store the term IDs along with the name of the vocabulary. Currently diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index a19d329..c171271 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -151,9 +151,9 @@ 'weight' => $i * 3 + $j, )); taxonomy_term_save($term); - $terms[] = $term->tid; - $term_vocabs[$term->tid] = 'taxonomy_' . $vocabulary->machine_name; - $parents[] = $term->tid; + $terms[] = $term->id(); + $term_vocabs[$term->id()] = 'taxonomy_' . $vocabulary->machine_name; + $parents[] = $term->id(); } } $node_id = 0;