diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 75c3386..03b20ec 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -262,6 +262,18 @@ function entity_load_unchanged($entity_type, $id) { } /** + * Permanently deletes a single entity. + * + * @param $entity_type + * The type of the entity. + * @param $id + * The id of the entity to delete. + */ +function entity_delete($entity_type, $id) { + entity_get_controller($entity_type)->delete(array($id)); +} + +/** * Deletes multiple entities permanently. * * @param $entity_type diff --git a/core/includes/file.inc b/core/includes/file.inc index f1c6ac9..ed3a2e4 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -911,40 +911,6 @@ function file_create_filename($basename, $directory) { } /** - * Deletes a file and its database record. - * - * Instead of directly deleting a file, it is strongly recommended to delete - * file usages instead. That will automatically mark the file as temporary and - * remove it during cleanup. - * - * @param $fid - * The file id. - * - * @see file_unmanaged_delete() - * @see file_usage_list() - */ -function file_delete($fid) { - return file_delete_multiple(array($fid)); -} - -/** - * Deletes files. - * - * Instead of directly deleting a file, it is strongly recommended to delete - * file usages instead. That will automatically mark the file as temporary and - * remove it during cleanup. - * - * @param $fid - * The file id. - * - * @see file_unmanaged_delete() - * @see file_usage_list() - */ -function file_delete_multiple(array $fids) { - entity_delete_multiple('file', $fids); -} - -/** * Deletes a file without database changes or hook invocations. * * This function should be used when the file to be deleted does not have an @@ -957,7 +923,7 @@ function file_delete_multiple(array $fids) { * TRUE for success or path does not exist, or FALSE in the event of an * error. * - * @see file_delete() + * @see entity_delete() * @see file_unmanaged_delete_recursive() */ function file_unmanaged_delete($path) { diff --git a/core/includes/form.inc b/core/includes/form.inc index 5d6b32e..966d7b9 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -4708,7 +4708,7 @@ function _form_set_class(&$element, $class = array()) { * ->range(0, $limit) * ->execute(); * foreach ($result as $row) { - * $node = node_load($row->nid, TRUE); + * $node = entity_load('node', $row->nid, TRUE); * $context['results'][] = $node->nid . ' : ' . check_plain($node->label()); * $context['sandbox']['progress']++; * $context['sandbox']['current_node'] = $node->nid; diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index b1d3b50..631ba6f 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1993,7 +1993,7 @@ function install_configure_form_submit($form, &$form_state) { } // We precreated user 1 with placeholder values. Let's save the real values. - $account = user_load(1); + $account = entity_load('user', 1); $account->init = $account->mail = $form_state['values']['account']['mail']; $account->roles = !empty($account->roles) ? $account->roles : array(); $account->status = 1; @@ -2002,7 +2002,7 @@ function install_configure_form_submit($form, &$form_state) { $account->name = $form_state['values']['account']['name']; $account->save(); // Load global $user and perform final login tasks. - $user = user_load(1); + $user = entity_load('user', 1); user_login_finalize(); // Record when this install ran. diff --git a/core/includes/token.inc b/core/includes/token.inc index a6f8064..28ea4b1 100644 --- a/core/includes/token.inc +++ b/core/includes/token.inc @@ -26,8 +26,8 @@ * @code * // Load a node and a user, then replace tokens in the text. * $text = 'On [date:short], [user:name] read [node:title].'; - * $node = node_load(1); - * $user = user_load(1); + * $node = entity_load('node', 1); + * $user = entity_load('user', 1); * * // [date:...] tokens use the current date automatically. * $data = array('node' => $node, 'user' => $user); diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index d4d6f0b..569ceae 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -158,7 +158,7 @@ function book_admin_edit_submit($form, &$form_state) { // Update the title if changed. if ($row['title']['#default_value'] != $values['title']) { - $node = node_load($values['nid']); + $node = entity_load('node', $values['nid']); $langcode = LANGUAGE_NOT_SPECIFIED; $node->title = $values['title']; $node->book['link_title'] = $values['title']; diff --git a/core/modules/book/book.module b/core/modules/book/book.module index fd4fac9..785e2e0 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -300,7 +300,7 @@ function book_block_view($delta = '') { // is no reason to run an additional menu tree query for each book. $book['in_active_trail'] = FALSE; // Check whether user can access the book link. - $book_node = node_load($book['nid']); + $book_node = entity_load('node', $book['nid']); $book['access'] = node_access('view', $book_node); $pseudo_tree[0]['link'] = $book; $book_menus[$book_id] = menu_tree_output($pseudo_tree); @@ -976,7 +976,7 @@ function book_node_predelete(Node $node) { ':plid' => $node->book['mlid'] )); foreach ($result as $child) { - $child_node = node_load($child->nid); + $child_node = entity_load('node', $child->nid); $child_node->book['bid'] = $child_node->nid; _book_update_outline($child_node); } @@ -1042,7 +1042,7 @@ function _book_parent_depth_limit($book_link) { * @see node_delete_confirm() */ function book_form_node_delete_confirm_alter(&$form, $form_state) { - $node = node_load($form['nid']['#value']); + $node = entity_load('node', $form['nid']['#value']); if (isset($node->book) && $node->book['has_children']) { $form['book_warning'] = array( @@ -1268,7 +1268,7 @@ function book_export_traverse($tree, $visit_func) { foreach ($tree as $data) { // Note- access checking is already performed when building the tree. - if ($node = node_load($data['link']['nid'])) { + if ($node = entity_load('node', $data['link']['nid'])) { $children = ''; if ($data['below']) { @@ -1364,7 +1364,7 @@ function book_node_type_update($type) { * * Like menu_link_load(), but adds additional data from the {book} table. * - * Do not call when loading a node, since this function may call node_load(). + * Do not call when loading a node, since this function may call entity_load(). * * @param $mlid * The menu link ID of the menu item. diff --git a/core/modules/book/book.pages.inc b/core/modules/book/book.pages.inc index 90b2192..0615ff6 100644 --- a/core/modules/book/book.pages.inc +++ b/core/modules/book/book.pages.inc @@ -79,7 +79,7 @@ function book_export($type, $nid) { function book_export_html($nid) { if (user_access('access printer-friendly version')) { $export_data = array(); - $node = node_load($nid); + $node = entity_load('node', $nid); if (isset($node->book)) { $tree = book_menu_subtree_data($node->book); $contents = book_export_traverse($tree, 'book_node_export'); diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index a1a88c4..fa6f2df 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -358,16 +358,16 @@ function testBookDelete() { $this->drupalGet('node/' . $this->book->nid . '/outline/remove'); $this->assertResponse('403', 'Deleting top-level book node properly forbidden.'); $this->drupalPost('node/' . $nodes[4]->nid . '/outline/remove', $edit, t('Remove')); - $node4 = node_load($nodes[4]->nid, TRUE); + $node4 = entity_load('node', $nodes[4]->nid, TRUE); $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.'); // Delete all child book nodes and retest top-level node deletion. foreach ($nodes as $node) { $nids[] = $node->nid; } - node_delete_multiple($nids); + entity_delete_multiple('node', $nids); $this->drupalPost('node/' . $this->book->nid . '/outline/remove', $edit, t('Remove')); - $node = node_load($this->book->nid, TRUE); + $node = entity_load('node', $this->book->nid, TRUE); $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.'); } } diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index dcbd1bc..37caba6 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -100,7 +100,7 @@ function comment_admin_overview($form, &$form_state, $arg) { $cids[] = $row->cid; $node_titles[] = $row->node_title; } - $comments = comment_load_multiple($cids); + $comments = entity_load_multiple('comment', $cids); // Build a table listing the appropriate comments. $options = array(); @@ -180,11 +180,11 @@ function comment_admin_overview_submit($form, &$form_state) { $cids = $form_state['values']['comments']; if ($operation == 'delete') { - comment_delete_multiple($cids); + entity_delete_multiple('comment', $cids); } else { foreach ($cids as $cid => $value) { - $comment = comment_load($value); + $comment = entity_load('comment', $value); if ($operation == 'unpublish') { $comment->status = COMMENT_NOT_PUBLISHED; @@ -192,7 +192,7 @@ function comment_admin_overview_submit($form, &$form_state) { elseif ($operation == 'publish') { $comment->status = COMMENT_PUBLISHED; } - comment_save($comment); + $comment->save(); } } drupal_set_message(t('The update has been performed.')); @@ -218,7 +218,7 @@ function comment_multiple_delete_confirm($form, &$form_state) { // array_filter() returns only elements with actual values. $comment_counter = 0; foreach (array_filter($edit['comments']) as $cid => $value) { - $comment = comment_load($cid); + $comment = entity_load('comment', $cid); if (is_object($comment) && is_numeric($comment->cid)) { $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField(); $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '
'; case 'node/%/edit': - $node = node_load($arg[1]); + $node = entity_load('node', $arg[1]); $type = node_type_load($node->type); return (!empty($type->help) ? '' . filter_xss_admin($type->help) . '
' : ''); } @@ -1028,39 +1028,20 @@ function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { } /** - * Loads node entities from the database. - * - * This function should be used whenever you need to load more than one node - * from the database. Nodes are loaded into memory and will not require - * database access if loaded again during the same page request. - * - * @param array $nids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * (optional) Whether to reset the internal node_load() cache. Defaults to - * FALSE. - * - * @return array - * An array of node entities indexed by nid. - * - * @see entity_load_multiple() - * @see Drupal\Core\Entity\EntityFieldQuery - */ -function node_load_multiple(array $nids = NULL, $reset = FALSE) { - return entity_load_multiple('node', $nids, $reset); -} - -/** * Loads a node entity from the database. * * @param int $nid * The node ID. * @param bool $reset - * (optional) Whether to reset the node_load_multiple() cache. Defaults to + * (optional) Whether to reset the entity_load_multiple() cache. Defaults to * FALSE. * * @return Drupal\node\Node|false * A fully-populated node entity, or FALSE if the node is not found. + * + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function node_load($nid = NULL, $reset = FALSE) { return entity_load('node', $nid, $reset); @@ -1114,40 +1095,6 @@ function node_submit($node) { } /** - * Saves changes to a node or adds a new node. - * - * @param Drupal\node\Node $node - * The $node entity to be saved. If $node->nid is - * omitted (or $node->is_new is TRUE), a new node will be added. - */ -function node_save(Node $node) { - $node->save(); -} - -/** - * Deletes a node. - * - * @param $nid - * A node ID. - */ -function node_delete($nid) { - node_delete_multiple(array($nid)); -} - -/** - * Deletes multiple nodes. - * - * @param $nids - * An array of node IDs. - * - * @see hook_node_predelete() - * @see hook_node_delete() - */ -function node_delete_multiple($nids) { - entity_delete_multiple('node', $nids); -} - -/** * Deletes a node revision. * * @param $revision_id @@ -1626,7 +1573,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) { $results = array(); foreach ($find as $item) { // Render the node. - $node = node_load($item->sid); + $node = entity_load('node', $item->sid); $build = node_view($node, 'search_result', $item->langcode); unset($build['#theme']); $node->rendered = drupal_render($build); @@ -1738,7 +1685,7 @@ function node_user_predelete($account) { ->condition('uid', $account->uid) ->execute() ->fetchCol(); - node_delete_multiple($nodes); + entity_delete_multiple('node', $nodes); // Delete old revisions. $revisions = db_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); foreach ($revisions as $revision) { @@ -1848,7 +1795,7 @@ function _node_revision_access(Node $node, $op = 'view', $account = NULL, $langc else { // First check the access to the default revision and finally, if the // node passed in is not the default revision then access to that, too. - $access[$cid] = node_access($op, node_load($node->nid), $account, $langcode) && ($node->isDefaultRevision() || node_access($op, $node, $account, $langcode)); + $access[$cid] = node_access($op, entity_load('node', $node->nid), $account, $langcode) && ($node->isDefaultRevision() || node_access($op, $node, $account, $langcode)); } } @@ -2240,7 +2187,7 @@ function node_get_recent($number = 10) { ->execute() ->fetchCol(); - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); return $nodes ? $nodes : array(); } @@ -2306,7 +2253,7 @@ function theme_node_recent_content($variables) { $output .= l($node->label(), 'node/' . $node->nid); $output .= theme('mark', array('type' => node_mark($node->nid, $node->changed))); $output .= ' '; return $output; @@ -2502,7 +2449,7 @@ function node_feed($nids = FALSE, $channel = array()) { $teaser = ($item_length == 'teaser'); // Load all nodes to be rendered. - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); $items = ''; foreach ($nodes as $node) { $item_text = ''; @@ -2555,7 +2502,7 @@ function node_feed($nids = FALSE, $channel = array()) { * Constructs a drupal_render() style array from an array of loaded nodes. * * @param $nodes - * An array of nodes as returned by node_load_multiple(). + * An array of nodes as returned by entity_load_multiple(). * @param $view_mode * (optional) View mode, e.g., 'full', 'teaser'... Defaults to 'teaser.' * @param $weight @@ -2603,7 +2550,7 @@ function node_page_default() { $nids = $select->execute()->fetchCol(); if (!empty($nids)) { - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); $build = node_view_multiple($nodes); // 'rss.xml' is a path, not a file, registered in node_menu(). @@ -2675,7 +2622,7 @@ function node_update_index() { // The indexing throttle should be aware of the number of language variants // of a node. $counter = 0; - foreach (node_load_multiple($nids) as $node) { + foreach (entity_load_multiple('node', $nids) as $node) { // Determine when the maximum number of indexable items is reached. $counter += 1 + count($node->translations()); if ($counter > $limit) { @@ -3573,7 +3520,7 @@ function node_access_rebuild($batch_mode = FALSE) { // Rebuild newest nodes first so that recent content becomes available quickly. $nids = db_query("SELECT nid FROM {node} ORDER BY nid DESC")->fetchCol(); foreach ($nids as $nid) { - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); // To preserve database integrity, only acquire grants if the node // loads successfully. if (!empty($node)) { @@ -3624,7 +3571,7 @@ function _node_access_rebuild_batch_operation(&$context) { // Process the next 20 nodes. $limit = 20; $nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", 0, $limit, array(':nid' => $context['sandbox']['current_node']))->fetchCol(); - $nodes = node_load_multiple($nids, TRUE); + $nodes = entity_load_multiple('node', $nids, TRUE); foreach ($nodes as $nid => $node) { // To preserve database integrity, only acquire grants if the node // loads successfully. diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 570ae88..6bbe8ac 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -142,7 +142,7 @@ function node_preview(Node $node) { } } elseif ($node->uid) { - $user = user_load($node->uid); + $user = entity_load('user', $node->uid); $node->name = $user->name; $node->picture = $user->picture; } @@ -228,8 +228,8 @@ function node_delete_confirm($form, &$form_state, $node) { */ function node_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - $node = node_load($form_state['values']['nid']); - node_delete($form_state['values']['nid']); + $node = entity_load('node', $form_state['values']['nid']); + entity_delete('node', $form_state['values']['nid']); watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->label())); drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_type_label($node), '%title' => $node->label()))); } diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 0bd1000..9fec4f9 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -157,7 +157,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr // Default values for the chained tokens handled below. case 'author': - $account = user_load($node->uid); + $account = entity_load('user', $node->uid); $name = user_format_name($account); $replacements[$original] = $sanitize ? check_plain($name) : $name; break; @@ -173,7 +173,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr } if ($author_tokens = token_find_with_prefix($tokens, 'author')) { - $author = user_load($node->uid); + $author = entity_load('user', $node->uid); $replacements += token_generate('user', $author_tokens, array('user' => $author), $options); } diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 6d78e43..c8e3e8f 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -354,7 +354,7 @@ function overlay_user_dismiss_message() { throw new AccessDeniedHttpException(); } - $account = user_load($user->uid); + $account = entity_load('user', $user->uid); $account->data['overlay_message_dismissed'] = 1; $account->save(); drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.')); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php index 421870d..467e602 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php @@ -47,7 +47,7 @@ function setUp() { */ function testTermAlias() { // Create a term in the default 'Tags' vocabulary with URL alias. - $vocabulary = taxonomy_vocabulary_load(1); + $vocabulary = entity_load('taxonomy_vocabulary', 1); $description = $this->randomName();; $edit = array(); $edit['name'] = $this->randomName(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollCreateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollCreateTest.php index 0618ce1..a23d198 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollCreateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollCreateTest.php @@ -38,7 +38,7 @@ function testPollCreate() { // Now add a new option to make sure that when we update the node the // option is displayed. - $node = node_load($poll_nid); + $node = entity_load('node', $poll_nid); $new_option = $this->randomName(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTokenReplaceTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTokenReplaceTest.php index 13f2f79..2ff16f2 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTokenReplaceTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTokenReplaceTest.php @@ -64,7 +64,7 @@ function testPollTokenReplacement() { $this->drupalPost('node/' . $poll_nid, $edit, t('Vote')); $this->drupalLogout(); - $poll = node_load($poll_nid, TRUE); + $poll = entity_load('node', $poll_nid, TRUE); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php index 4d9299a..60ac5b2 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php @@ -70,7 +70,7 @@ function testPollTranslate() { // Translate the Dutch poll. $this->drupalGet('node/add/poll', array('query' => array('translation' => $poll_nid, 'target' => 'en'))); - $dutch_poll = node_load($poll_nid); + $dutch_poll = entity_load('node', $poll_nid); // Check that the vote count values didn't get copied from the Dutch poll // and are set to 0. diff --git a/core/modules/poll/poll.module b/core/modules/poll/poll.module index c85f121..76a360e 100644 --- a/core/modules/poll/poll.module +++ b/core/modules/poll/poll.module @@ -148,7 +148,7 @@ function poll_block_view($delta = '') { $record = $select->execute()->fetchObject(); if ($record) { - $poll = node_load($record->nid); + $poll = entity_load('node', $record->nid); if ($poll->nid) { $poll = poll_block_latest_poll_view($poll); $block['subject'] = t('Poll'); @@ -987,7 +987,7 @@ function poll_cancel_form($form, &$form_state, $nid) { */ function poll_cancel($form, &$form_state) { global $user; - $node = node_load($form['#nid']); + $node = entity_load('node', $form['#nid']); db_delete('poll_vote') ->condition('nid', $node->nid) diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php index e4f6fe4..3b5b387 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php @@ -127,7 +127,7 @@ function _testBasicTrackerRdfaMarkup(Node $node) { $this->assertTrue($tracker_replies, t('Num replies property and content attributes found on @user content.', array('@user'=> $user))); // Need to query database directly to obtain last_activity_date because - // it cannot be accessed via node_load(). + // it cannot be accessed via entity_load(). $result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid)); foreach ($result as $node) { $expected_last_activity_date = $node->changed; diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 782c06f..df7eb54 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -667,7 +667,7 @@ function rdf_preprocess_username(&$variables) { // $variables['account'] is a pseudo account object, and as such, does not // contain the RDF mappings for the user. In the case of nodes and comments, // it contains the mappings for the node or comment object instead. However, - // while the RDF mappings are available from a full user_load(), this should + // while the RDF mappings are available from a full entity_load(), this should // be avoided for performance reasons. Since the type and bundle for users is // already known, call rdf_mapping_load() directly. $rdf_mapping = rdf_mapping_load('user', 'user'); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php index cb35b06..5289146 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php @@ -90,9 +90,9 @@ function testSearchCommentCountToggle() { // Test comment count display for nodes with comment status set to Closed $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_CLOSED; - node_save($this->searchable_nodes['0 comments']); + $this->searchable_nodes['0 comments']->save(); $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_CLOSED; - node_save($this->searchable_nodes['1 comment']); + $this->searchable_nodes['1 comment']->save(); $this->drupalPost('', $edit, t('Search')); $this->assertNoText(t('0 comments'), t('Empty comment count does not display for nodes with comment status set to Closed')); @@ -100,9 +100,9 @@ function testSearchCommentCountToggle() { // Test comment count display for nodes with comment status set to Hidden $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_HIDDEN; - node_save($this->searchable_nodes['0 comments']); + $this->searchable_nodes['0 comments']->save(); $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_HIDDEN; - node_save($this->searchable_nodes['1 comment']); + $this->searchable_nodes['1 comment']->save(); $this->drupalPost('', $edit, t('Search')); $this->assertNoText(t('0 comments'), t('Empty comment count does not display for nodes with comment status set to Hidden')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index 8df2e99..872ad7e 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -89,7 +89,7 @@ function testSearchResultsComment() { 'search_block_form' => "'" . $edit_comment['subject'] . "'", ); $this->drupalPost('', $edit, t('Search')); - $node2 = node_load($node->nid, TRUE); + $node2 = entity_load('node', $node->nid, TRUE); $this->assertText($node2->label(), t('Node found in search results.')); $this->assertText($edit_comment['subject'], t('Comment subject found in search results.')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php index a57e483..03e8a1e 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php @@ -187,7 +187,7 @@ function testHTMLRankings() { $this->assertEqual($set[0]['node']->nid, $node->nid, 'Search tag ranking for "<' . $tag . '>" order.'); // Delete node so it doesn't show up in subsequent search results. - node_delete($node->nid); + entity_delete('node', $node->nid); } } diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 3dcea0d..81808ec 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -225,7 +225,7 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $results = array(); foreach ($find as $item) { // Render the node. - $node = node_load($item->sid); + $node = entity_load('node', $item->sid); $build = node_view($node, 'search_result', $item->langcode); unset($build['#theme']); $node->rendered = drupal_render($build); @@ -355,7 +355,7 @@ function hook_update_index() { $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit); foreach ($result as $node) { - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); // Save the changed time of the most recent indexed node, for the search // results half-life calculation. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 24bf1f2..c1c0af9 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -516,7 +516,7 @@ protected function checkPermissions(array $permissions, $reset = FALSE) { * $this->drupalLogin($account); * // Load real user object. * $pass_raw = $account->pass_raw; - * $account = user_load($account->uid); + * $account = entity_load('user', $account->uid); * $account->pass_raw = $pass_raw; * @endcode * diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php index 6824e34..226d36c 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php @@ -122,7 +122,7 @@ function testDeleteNode() { ->fetchAssoc(); $this->assertEqual($result['nid'], $this->test_node->nid, 'Verifying that the node counter is incremented.'); - node_delete($this->test_node->nid); + entity_delete('node', $this->test_node->nid); $result = db_select('node_counter', 'n') ->fields('n', array('nid')) @@ -144,7 +144,7 @@ function testDeleteUser() { $this->drupalLogin($account); $this->drupalGet('node/' . $this->test_node->nid); - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->drupalGet('user/' . $account->uid . '/edit'); $this->drupalPost(NULL, NULL, t('Cancel account')); @@ -157,7 +157,7 @@ function testDeleteUser() { preg_match('@http.+?(user/\d+/cancel/confirm/\d+/[^\s]+)@', $mail['body'], $matches); $path = $matches[1]; $this->drupalGet($path); - $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.'); + $this->assertFalse(entity_load('user', $account->uid, TRUE), 'User is not found in the database.'); $this->drupalGet('admin/reports/visitors'); $this->assertNoText($account->name, 'Did not find user in visitor statistics.'); diff --git a/core/modules/statistics/statistics.pages.inc b/core/modules/statistics/statistics.pages.inc index 6cf110c..0c4b951 100644 --- a/core/modules/statistics/statistics.pages.inc +++ b/core/modules/statistics/statistics.pages.inc @@ -17,7 +17,7 @@ * @see statistics_menu() */ function statistics_node_tracker() { - if ($node = node_load(arg(1))) { + if ($node = entity_load('node', arg(1))) { $header = array( array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), array('data' => t('Referrer'), 'field' => 'a.url'), @@ -86,7 +86,7 @@ function statistics_node_tracker() { * @see statistics_menu() */ function statistics_user_tracker() { - if ($account = user_load(arg(1))) { + if ($account = entity_load('user', arg(1))) { $header = array( array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'), diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index b61987e..e64f2d3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -114,7 +114,7 @@ function testFormatDate() { drupal_save_session(FALSE); // Save the original user and language and then replace it with the test user and language. $real_user = $user; - $user = user_load($test_user->uid, TRUE); + $user = entity_load('user', $test_user->uid, TRUE); $real_language = $language_interface->langcode; $language_interface->langcode = $user->preferred_langcode; // Simulate a Drupal bootstrap with the logged-in user. 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 4afb574..3587f3c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -97,7 +97,7 @@ public function testCommentHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - comment_save($comment); + $comment->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_comment_presave called', @@ -107,7 +107,7 @@ public function testCommentHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $comment = comment_load($comment->cid); + $comment = entity_load('comment', $comment->cid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type comment', @@ -116,7 +116,7 @@ public function testCommentHooks() { $_SESSION['entity_crud_hook_test'] = array(); $comment->subject = 'New subject'; - comment_save($comment); + $comment->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_comment_presave called', @@ -126,7 +126,7 @@ public function testCommentHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - comment_delete($comment->cid); + entity_delete('comment', $comment->cid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_comment_predelete called', @@ -163,7 +163,7 @@ public function testFileHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $file = file_load($file->fid); + $file = entity_load('file', $file->fid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type file', @@ -219,7 +219,7 @@ public function testNodeHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type node', @@ -238,7 +238,7 @@ public function testNodeHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - node_delete($node->nid); + entity_delete('node', $node->nid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_node_predelete called', @@ -259,7 +259,7 @@ public function testTaxonomyTermHooks() { 'description' => NULL, 'module' => 'entity_crud_hook_test', )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); $term = entity_create('taxonomy_term', array( 'vid' => $vocabulary->vid, @@ -269,7 +269,7 @@ public function testTaxonomyTermHooks() { 'format' => 1, )); $_SESSION['entity_crud_hook_test'] = array(); - taxonomy_term_save($term); + $term->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_term_presave called', @@ -279,7 +279,7 @@ public function testTaxonomyTermHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $term = taxonomy_term_load($term->tid); + $term = entity_load('taxonomy_term', $term->tid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type taxonomy_term', @@ -288,7 +288,7 @@ public function testTaxonomyTermHooks() { $_SESSION['entity_crud_hook_test'] = array(); $term->name = 'New name'; - taxonomy_term_save($term); + $term->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_term_presave called', @@ -298,7 +298,7 @@ public function testTaxonomyTermHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - taxonomy_term_delete($term->tid); + entity_delete('taxonomy_term', $term->tid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_term_predelete called', @@ -320,7 +320,7 @@ public function testTaxonomyVocabularyHooks() { 'module' => 'entity_crud_hook_test', )); $_SESSION['entity_crud_hook_test'] = array(); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_vocabulary_presave called', @@ -330,7 +330,7 @@ public function testTaxonomyVocabularyHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $vocabulary = taxonomy_vocabulary_load($vocabulary->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vocabulary->vid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary', @@ -339,7 +339,7 @@ public function testTaxonomyVocabularyHooks() { $_SESSION['entity_crud_hook_test'] = array(); $vocabulary->name = 'New name'; - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_vocabulary_presave called', @@ -349,7 +349,7 @@ public function testTaxonomyVocabularyHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - taxonomy_vocabulary_delete($vocabulary->vid); + entity_delete('taxonomy_vocabulary', $vocabulary->vid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_taxonomy_vocabulary_predelete called', @@ -381,7 +381,7 @@ public function testUserHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - user_load($account->uid); + entity_load('user', $account->uid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type user', @@ -400,7 +400,7 @@ public function testUserHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - user_delete($account->uid); + entity_delete('user', $account->uid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_user_predelete called', diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php index f3275a7..cbd67fb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php @@ -59,7 +59,7 @@ function testUpdateAccess() { $this->assertResponse(200); // Access the update page as user 1. - $user1 = user_load(1); + $user1 = entity_load('user', 1); $user1->pass_raw = user_password(); require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'core/includes/password.inc'); $user1->pass = user_hash_password(trim($user1->pass_raw)); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 65c30de..79e1fbb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -66,8 +66,8 @@ public function testLanguageUpgrade() { $translation_source_nid = 52; $translation_nid = 53; // Check directly for the $node->langcode property. - $this->assertEqual(node_load($language_none_nid)->langcode, LANGUAGE_NOT_SPECIFIED, "'language' property was renamed to 'langcode' for LANGUAGE_NOT_SPECIFIED node."); - $this->assertEqual(node_load($spanish_nid)->langcode, 'ca', "'language' property was renamed to 'langcode' for Catalan node."); + $this->assertEqual(entity_load('node', $language_none_nid)->langcode, LANGUAGE_NOT_SPECIFIED, "'language' property was renamed to 'langcode' for LANGUAGE_NOT_SPECIFIED node."); + $this->assertEqual(entity_load('node', $spanish_nid)->langcode, 'ca', "'language' property was renamed to 'langcode' for Catalan node."); // Check that the translation table works correctly. $this->drupalGet("node/$translation_source_nid/translate"); $this->assertResponse(200, 'The translated node has a proper translation table.'); diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 0f6d668..39349ab 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2090,7 +2090,7 @@ function hook_mail($key, &$message, $params) { ); if ($context['hook'] == 'taxonomy') { $entity = $params['entity']; - $vocabulary = taxonomy_vocabulary_load($entity->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $entity->vid); $variables += array( '%term_name' => $entity->name, '%term_description' => $entity->description, @@ -3610,7 +3610,7 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr } if ($author_tokens = token_find_with_prefix($tokens, 'author')) { - $author = user_load($node->uid); + $author = entity_load('user', $node->uid); $replacements += token_generate('user', $author_tokens, array('user' => $author), $options); } diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index a5e7ad2..6e065f2 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -249,7 +249,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a break; case 'owner': - $account = user_load($file->uid); + $account = entity_load('user', $file->uid); $name = user_format_name($account); $replacements[$original] = $sanitize ? check_plain($name) : $name; break; @@ -260,7 +260,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a $replacements += token_generate('date', $date_tokens, array('date' => $file->timestamp), $options); } - if (($owner_tokens = token_find_with_prefix($tokens, 'owner')) && $account = user_load($file->uid)) { + if (($owner_tokens = token_find_with_prefix($tokens, 'owner')) && $account = entity_load('user', $file->uid)) { $replacements += token_generate('user', $owner_tokens, array('user' => $account), $options); } } diff --git a/core/modules/system/tests/modules/url_alter_test/url_alter_test.module b/core/modules/system/tests/modules/url_alter_test/url_alter_test.module index a5ca13d..691e09e 100644 --- a/core/modules/system/tests/modules/url_alter_test/url_alter_test.module +++ b/core/modules/system/tests/modules/url_alter_test/url_alter_test.module @@ -58,7 +58,7 @@ function url_alter_test_url_inbound_alter(&$path, $original_path, $path_language function url_alter_test_url_outbound_alter(&$path, &$options, $original_path) { // Rewrite user/uid to user/username. if (preg_match('!^user/([0-9]+)(/.*)?!', $path, $matches)) { - if ($account = user_load($matches[1])) { + if ($account = entity_load('user', $matches[1])) { $matches += array(2 => ''); $path = 'user/' . $account->name . $matches[2]; } 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 3f4d510..520d1eb 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 @@ -38,7 +38,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $tags = array(); foreach ($items as $item) { - $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']); + $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : entity_load('taxonomy_term', $item['tid']); } $element += array( '#type' => 'textfield', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index c7ee415..146d225 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -19,7 +19,7 @@ class TermFormController extends EntityFormController { * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $term) { - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $term->vid); $parent = array_keys(taxonomy_term_load_parents($term->tid)); $form_state['taxonomy']['parent'] = $parent; @@ -157,7 +157,7 @@ public function submit(array $form, array &$form_state) { public function save(array $form, array &$form_state) { $term = $this->getEntity($form_state); - $status = taxonomy_term_save($term); + $status = $term->save(); switch ($status) { case SAVED_NEW: drupal_set_message(t('Created new term %term.', array('%term' => $term->label()))); @@ -188,7 +188,7 @@ public function save(array $form, array &$form_state) { // hierarchy, update the vocabulary immediately. elseif ($current_parent_count > $previous_parent_count && $form_state['taxonomy']['vocabulary']->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE) { $form_state['taxonomy']['vocabulary']->hierarchy = $current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE; - taxonomy_vocabulary_save($form_state['taxonomy']['vocabulary']); + $form_state['taxonomy']['vocabulary']->save(); } $form_state['values']['tid'] = $term->tid; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index c77cad5..848a5cf 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -30,7 +30,7 @@ public function create(array $values) { // @todo Move to Term::bundle() once field API has been converted // to make use of it. if (!isset($entity->vocabulary_machine_name) && isset($entity->vid)) { - $vocabulary = taxonomy_vocabulary_load($entity->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $entity->vid); $entity->vocabulary_machine_name = $vocabulary->machine_name; } // Save new terms with no parents by default. @@ -92,7 +92,7 @@ protected function postDelete($entities) { ->execute(); if (!empty($orphans)) { - taxonomy_term_delete_multiple($orphans); + entity_delete_multiple('taxonomy_term', $orphans); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php index e9bb9f6..68cff41 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php @@ -62,19 +62,19 @@ function testTaxonomyTermHooks() { ); $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); taxonomy_terms_static_reset(); - $term = taxonomy_term_load($term->tid); + $term = entity_load('taxonomy_term', $term->tid); $this->assertEqual($edit['antonym'], $term->antonym, '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 = entity_load('taxonomy_term', $term->tid); 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.'); // Delete the term. - taxonomy_term_delete($term->tid); + entity_delete('taxonomy_term', $term->tid); $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->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 657e9b4..04c67ad 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php @@ -8,7 +8,7 @@ namespace Drupal\taxonomy\Tests; /** - * Test the taxonomy_term_load_multiple() function. + * Test the entity_load_multiple() function. */ class LoadMultipleTest extends TaxonomyTestBase { @@ -28,7 +28,7 @@ function setUp() { /** * Create a vocabulary and some taxonomy terms, ensuring they're loaded - * correctly using taxonomy_term_load_multiple(). + * correctly using entity_load_multiple(). */ function testTaxonomyTermMultipleLoad() { // Create a vocabulary. @@ -46,14 +46,14 @@ function testTaxonomyTermMultipleLoad() { $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count))); // Load the same terms again by tid. - $terms2 = taxonomy_term_load_multiple(array_keys($terms)); + $terms2 = entity_load_multiple('taxonomy_term', array_keys($terms)); $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.'); $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.'); // 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); + entity_delete('taxonomy_term', $deleted->tid); + $deleted_term = entity_load('taxonomy_term', $deleted->tid); $this->assertFalse($deleted_term); // Load terms from the vocabulary by vid. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php index 6f4dcb2..d94a661 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php @@ -44,7 +44,7 @@ function createVocabulary() { 'nodes' => array('article' => 'article'), 'weight' => mt_rand(0, 10), )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); return $vocabulary; } @@ -60,7 +60,7 @@ function createTerm($vocabulary) { 'vid' => $vocabulary->vid, 'langcode' => LANGUAGE_NOT_SPECIFIED, )); - taxonomy_term_save($term); + $term->save(); return $term; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 37cbf4e..840d852 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -105,7 +105,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->assertText($term2->name, 'Term 2 name is displayed.'); // Delete vocabulary 2. - taxonomy_vocabulary_delete($this->vocabulary2->vid); + entity_delete('taxonomy_vocabulary', $this->vocabulary2->vid); // Re-render the content. $entity = field_test_entity_test_load($id); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 34065e1..838911a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -129,7 +129,7 @@ function testTaxonomyTermFieldWidgets() { $this->assertText($term->label(), 'Term label is displayed.'); // Delete the vocabulary and verify that the widget is gone. - taxonomy_vocabulary_delete($this->vocabulary->vid); + entity_delete('taxonomy_vocabulary', $this->vocabulary->vid); $this->drupalGet('test-entity/add/test_bundle'); $this->assertNoFieldByName("{$this->field_name}[$langcode]", '', 'Widget is not displayed'); } @@ -158,7 +158,7 @@ function testTaxonomyTermFieldChangeMachineName() { // Change the machine name. $new_name = drupal_strtolower($this->randomName()); $this->vocabulary->machine_name = $new_name; - taxonomy_vocabulary_save($this->vocabulary); + $this->vocabulary->save(); // Check that the field instance is still attached to the vocabulary. $field = field_info_field($this->field_name); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 31d01c5..106d703 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -209,7 +209,7 @@ function testTaxonomyTermHierarchyBreadcrumbs() { $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); $term1->parent = array($term2->tid); - taxonomy_term_save($term1); + $term1->save(); // Verify that the page breadcrumbs include a link to the parent term. $this->drupalGet('taxonomy/term/' . $term1->tid); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index b2603d6..7723845 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -66,7 +66,7 @@ function testTaxonomyTermHierarchy() { $term2 = $this->createTerm($this->vocabulary); // Check that hierarchy is flat. - $vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->vid); $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.'); // Edit $term2, setting $term1 as parent. @@ -81,15 +81,15 @@ function testTaxonomyTermHierarchy() { $this->assertTrue(isset($parents[$term1->tid]), 'Parent found correctly.'); // Load and save a term, confirming that parents are still set. - $term = taxonomy_term_load($term2->tid); - taxonomy_term_save($term); + $term = entity_load('taxonomy_term', $term2->tid); + $term->save(); $parents = taxonomy_term_load_parents($term2->tid); $this->assertTrue(isset($parents[$term1->tid]), '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); - taxonomy_term_save($term2); + $term2->save(); $parents = taxonomy_term_load_parents($term2->tid); $this->assertTrue(isset($parents[$term1->tid]) && isset($parents[$term3->tid]), 'Both parents found successfully.'); } @@ -230,15 +230,15 @@ function testTermAutocompletion() { // Add a term with a slash in the name. $first_term = $this->createTerm($this->vocabulary); $first_term->name = '10/16/2011'; - taxonomy_term_save($first_term); + $first_term->save(); // Add another term that differs after the slash character. $second_term = $this->createTerm($this->vocabulary); $second_term->name = '10/17/2011'; - taxonomy_term_save($second_term); + $second_term->save(); // Add another term that has both a comma and a slash character. $third_term = $this->createTerm($this->vocabulary); $third_term->name = 'term with, a comma and / a slash'; - taxonomy_term_save($third_term); + $third_term->save(); // Try to autocomplete a term name that matches both terms. // We should get both term in a json encoded string. @@ -326,7 +326,7 @@ function testTermInterface() { $this->assertPattern('|class="taxonomy-term-description"|', 'Term page displayed the term description element.'); // Check that it does NOT show a description when description is blank. $term->description = ''; - taxonomy_term_save($term); + $term->save(); $this->drupalGet('taxonomy/term/' . $term->tid); $this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.'); @@ -470,7 +470,7 @@ function testTaxonomyGetTermByName() { 'name' => $term->name, 'vid' => $new_vocabulary->vid, )); - taxonomy_term_save($new_term); + $new_term->save(); // Load multiple terms with the same name. $terms = taxonomy_term_load_multiple_by_name($term->name); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php index 22f9dcb..e9228e7 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php @@ -24,12 +24,12 @@ function testTermDelete() { $vocabulary = $this->createVocabulary(); $valid_term = $this->createTerm($vocabulary); // Delete a valid term. - taxonomy_term_delete($valid_term->tid); + entity_delete('taxonomy_term', $valid_term->tid); $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid)); $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion'); // Delete an invalid term. Should not throw any notices. - taxonomy_term_delete(42); + entity_delete('taxonomy_term', 42); } /** @@ -45,13 +45,13 @@ function testTaxonomyVocabularyTree() { // $term[2] is a child of 1 and 5. $term[2]->parent = array($term[1]->tid, $term[5]->tid); - taxonomy_term_save($term[2]); + $term[2]->save(); // $term[3] is a child of 2. $term[3]->parent = array($term[2]->tid); - taxonomy_term_save($term[3]); + $term[3]->save(); // $term[5] is a child of 4. $term[5]->parent = array($term[4]->tid); - taxonomy_term_save($term[5]); + $term[5]->save(); /** * Expected tree: diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php index 6197fdb..816a3f3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php @@ -85,7 +85,7 @@ function testTaxonomyAdminChangingWeights() { $this->createVocabulary(); } // Get all vocabularies and change their weights. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $edit = array(); foreach ($vocabularies as $key => $vocabulary) { $vocabulary->weight = -$vocabulary->weight; @@ -96,7 +96,7 @@ function testTaxonomyAdminChangingWeights() { $this->drupalPost('admin/structure/taxonomy', $edit, t('Save')); // Load the vocabularies from the database. - $new_vocabularies = taxonomy_vocabulary_load_multiple(); + $new_vocabularies = entity_load_multiple('taxonomy_vocabulary'); // Check that the weights are saved in the database correctly. foreach ($vocabularies as $key => $vocabulary) { @@ -109,12 +109,12 @@ function testTaxonomyAdminChangingWeights() { */ function testTaxonomyAdminNoVocabularies() { // Delete all vocabularies. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); foreach ($vocabularies as $key => $vocabulary) { - taxonomy_vocabulary_delete($key); + entity_delete('taxonomy_vocabulary', $key); } // Confirm that no vocabularies are found in the database. - $this->assertFalse(taxonomy_vocabulary_load_multiple(), 'No vocabularies found in the database.'); + $this->assertFalse(entity_load_multiple('taxonomy_vocabulary'), 'No vocabularies found in the database.'); $this->drupalGet('admin/structure/taxonomy'); // Check the default message for no vocabularies. $this->assertText(t('No vocabularies available.'), 'No vocabularies were found.'); @@ -133,10 +133,10 @@ function testTaxonomyAdminDeletingVocabulary() { $this->assertText(t('Created new vocabulary'), 'New vocabulary was created.'); // Check the created vocabulary. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vid = $vocabularies[count($vocabularies) - 1]->vid; entity_get_controller('taxonomy_vocabulary')->resetCache(); - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); $this->assertTrue($vocabulary, 'Vocabulary found in database.'); // Delete the vocabulary. @@ -149,6 +149,6 @@ function testTaxonomyAdminDeletingVocabulary() { $this->drupalPost(NULL, NULL, t('Delete')); $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), 'Vocabulary deleted.'); entity_get_controller('taxonomy_vocabulary')->resetCache(); - $this->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary is not found in the database')); + $this->assertFalse(entity_load('taxonomy_vocabulary', $vid), t('Vocabulary is not found in the database')); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index 9080ef2..0459ab2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -41,9 +41,9 @@ function setUp() { */ function testTaxonomyVocabularyLoadReturnFalse() { // Load a vocabulary that doesn't exist. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vid = count($vocabularies) + 1; - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); // This should not return an object because no such vocabulary exists. $this->assertTrue(empty($vocabulary), 'No object loaded.'); @@ -51,7 +51,7 @@ function testTaxonomyVocabularyLoadReturnFalse() { $this->createVocabulary(); // Load the vocabulary with the same $vid from earlier. // This should return a vocabulary object since it now matches a real vid. - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); $this->assertTrue(!empty($vocabulary) && is_object($vocabulary), 'Vocabulary is an object.'); $this->assertEqual($vocabulary->vid, $vid, 'Valid vocabulary vid is the same as our previously invalid one.'); } @@ -61,8 +61,8 @@ function testTaxonomyVocabularyLoadReturnFalse() { */ function testTaxonomyVocabularyDeleteWithTerms() { // Delete any existing vocabularies. - foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); + foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { + entity_delete('taxonomy_vocabulary', $vocabulary->vid); } // Assert that there are no terms left. @@ -77,14 +77,14 @@ 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); - taxonomy_term_save($terms[2]); + $terms[2]->save(); $terms[4]->parent = array($terms[1]->tid, $terms[2]->tid); - taxonomy_term_save($terms[4]); + $terms[4]->save(); // Assert that there are now 5 terms. $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); - taxonomy_vocabulary_delete($vocabulary->vid); + entity_delete('taxonomy_vocabulary', $vocabulary->vid); // Assert that there are no terms left. $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); @@ -94,7 +94,7 @@ function testTaxonomyVocabularyDeleteWithTerms() { * Ensure that the vocabulary static reset works correctly. */ function testTaxonomyVocabularyLoadStaticReset() { - $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid); + $original_vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->vid); $this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.'); $this->assertEqual($this->vocabulary->name, $original_vocabulary->name, 'Vocabulary loaded successfully.'); @@ -102,16 +102,16 @@ function testTaxonomyVocabularyLoadStaticReset() { $vocabulary = $original_vocabulary; $vocabulary->name = $this->randomName(); $vocabulary->description = $this->randomName(); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); // Load the vocabulary. - $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->vid); + $new_vocabulary = entity_load('taxonomy_vocabulary', $original_vocabulary->vid); $this->assertEqual($new_vocabulary->name, $vocabulary->name); $this->assertEqual($new_vocabulary->name, $vocabulary->name); // Delete the vocabulary. - taxonomy_vocabulary_delete($this->vocabulary->vid); - $vocabularies = taxonomy_vocabulary_load_multiple(); + entity_delete('taxonomy_vocabulary', $this->vocabulary->vid); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $this->assertTrue(!isset($vocabularies[$this->vocabulary->vid]), 'The vocabulary was deleted.'); } @@ -121,36 +121,36 @@ function testTaxonomyVocabularyLoadStaticReset() { function testTaxonomyVocabularyLoadMultiple() { // Delete any existing vocabularies. - foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); + foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { + entity_delete('taxonomy_vocabulary', $vocabulary->vid); } // Create some vocabularies and assign weights. $vocabulary1 = $this->createVocabulary(); $vocabulary1->weight = 0; - taxonomy_vocabulary_save($vocabulary1); + $vocabulary1->save(); $vocabulary2 = $this->createVocabulary(); $vocabulary2->weight = 1; - taxonomy_vocabulary_save($vocabulary2); + $vocabulary2->save(); $vocabulary3 = $this->createVocabulary(); $vocabulary3->weight = 2; - taxonomy_vocabulary_save($vocabulary3); + $vocabulary3->save(); // Fetch the names for all vocabularies, confirm that they are keyed by // machine name. $names = taxonomy_vocabulary_get_names(); $this->assertEqual($names[$vocabulary1->machine_name]->name, $vocabulary1->name, 'Vocabulary 1 name found.'); - // Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(). + // Fetch all of the vocabularies using entity_load_multiple(). // Confirm that the vocabularies are ordered by weight. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary was found in the vocabularies array.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary was found in the vocabularies array.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary was found in the vocabularies array.'); - // Fetch the vocabularies with taxonomy_vocabulary_load_multiple(), specifying IDs. + // Fetch the vocabularies with entity_load_multiple(), specifying IDs. // Ensure they are returned in the same order as the original array. - $vocabularies = taxonomy_vocabulary_load_multiple(array($vocabulary3->vid, $vocabulary2->vid, $vocabulary1->vid)); + $vocabularies = entity_load_multiple('taxonomy_vocabulary', array($vocabulary3->vid, $vocabulary2->vid, $vocabulary1->vid)); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary loaded successfully by ID.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary loaded successfully by ID.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by ID.'); @@ -159,8 +159,9 @@ function testTaxonomyVocabularyLoadMultiple() { $vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name))); $this->assertEqual($vocabulary->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name.'); - // Fetch vocabulary 1 by name and ID. - $this->assertEqual(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name)))->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name and ID.'); + // Fetch vocabulary 1 by ID. + $entity = entity_load_multiple_by_properties('taxonomy_vocabulary', array('vid' => $vocabulary1->vid, 'name' => $vocabulary1->name)); + $this->assertEqual(current($entity)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name and ID.'); } /** @@ -184,7 +185,7 @@ function testTaxonomyVocabularyChangeMachineName() { $old_name = $this->vocabulary->machine_name; $new_name = drupal_strtolower($this->randomName()); $this->vocabulary->machine_name = $new_name; - taxonomy_vocabulary_save($this->vocabulary); + $this->vocabulary->save(); // Check that entity bundles are properly updated. $info = entity_get_info('taxonomy_term'); @@ -222,7 +223,7 @@ function testUninstallReinstall() { // module was uninstalled. Creating a new field with the same name and // an instance of this field on the same bundle name should be successful. $this->vocabulary->enforceIsNew(); - taxonomy_vocabulary_save($this->vocabulary); + $this->vocabulary->save(); unset($this->field['id']); field_create_field($this->field); field_create_instance($this->instance); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index bdeea4c..86b6412 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -125,7 +125,7 @@ public function save(array $form, array &$form_state) { // Prevent leading and trailing spaces in vocabulary names. $vocabulary->name = trim($vocabulary->name); - switch (taxonomy_vocabulary_save($vocabulary)) { + switch ($vocabulary->save()) { case SAVED_NEW: drupal_set_message(t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php index dd5b478..b817594 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -44,7 +44,7 @@ protected function postSave(EntityInterface $entity, $update) { protected function preDelete($entities) { // Only load terms without a parent, child terms will get deleted too. $tids = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid IN (:vids) AND th.parent = 0', array(':vids' => array_keys($entities)))->fetchCol(); - taxonomy_term_delete_multiple($tids); + entity_delete_multiple('taxonomy_term', $tids); } /** diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index be305f6..c58632a 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -16,7 +16,7 @@ * @see theme_taxonomy_overview_vocabularies() */ function taxonomy_overview_vocabularies($form) { - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $form['#tree'] = TRUE; foreach ($vocabularies as $vocabulary) { $form[$vocabulary->vid]['#vocabulary'] = $vocabulary; @@ -68,7 +68,7 @@ function taxonomy_overview_vocabularies_submit($form, &$form_state) { foreach ($form_state['values'] as $vid => $vocabulary) { if (is_numeric($vid) && $form[$vid]['#vocabulary']->weight != $form_state['values'][$vid]['weight']) { $form[$vid]['#vocabulary']->weight = $form_state['values'][$vid]['weight']; - taxonomy_vocabulary_save($form[$vid]['#vocabulary']); + $form[$vid]['#vocabulary']->save(); } } drupal_set_message(t('The configuration options have been saved.')); @@ -432,7 +432,7 @@ function taxonomy_overview_terms_submit($form, &$form_state) { // Update the vocabulary hierarchy to flat or single hierarchy. if ($vocabulary->hierarchy != $hierarchy) { $vocabulary->hierarchy = $hierarchy; - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); } drupal_set_message(t('The configuration options have been saved.')); } @@ -547,7 +547,7 @@ 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_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->vid);; + $form_state['taxonomy']['vocabulary'] = entity_load('taxonomy_vocabulary', $term->vid); $form['type'] = array('#type' => 'value', '#value' => 'term'); $form['name'] = array('#type' => 'value', '#value' => $term->name); $form['vocabulary_machine_name'] = array('#type' => 'value', '#value' => $term->vocabulary_machine_name); @@ -567,7 +567,7 @@ function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { * @see taxonomy_term_confirm_delete() */ function taxonomy_term_confirm_delete_submit($form, &$form_state) { - taxonomy_term_delete($form_state['values']['tid']); + entity_delete('taxonomy_term', $form_state['values']['tid']); taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state['values']); drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name']))); watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); @@ -585,7 +585,7 @@ function taxonomy_term_confirm_delete_submit($form, &$form_state) { * @see taxonomy_vocabulary_confirm_delete_submit() */ function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) { - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); // Always provide entity id in the same form key as in the entity edit form. $form['vid'] = array('#type' => 'value', '#value' => $vid); @@ -610,7 +610,7 @@ function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) { * @see taxonomy_vocabulary_confirm_delete() */ function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) { - $status = taxonomy_vocabulary_delete($form_state['values']['vid']); + $status = entity_delete('taxonomy_vocabulary', $form_state['values']['vid']); drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name']))); watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); $form_state['redirect'] = 'admin/structure/taxonomy'; @@ -625,7 +625,7 @@ function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) { * @see taxonomy_vocabulary_confirm_reset_alphabetical_submit() */ function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid) { - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); $form['vid'] = array('#type' => 'value', '#value' => $vid); diff --git a/core/modules/taxonomy/taxonomy.api.php b/core/modules/taxonomy/taxonomy.api.php index 6657624..1c5ef5e 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -16,7 +16,7 @@ * Act on taxonomy vocabularies when loaded. * * Modules implementing this hook can act on the vocabulary objects before they - * are returned by taxonomy_vocabulary_load_multiple(). + * are returned by entity_load_multiple(). * * @param array $vocabularies * An array of taxonomy vocabulary entities. @@ -74,15 +74,14 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Vocabulary $vocabulary) /** * Act before taxonomy vocabulary deletion. * - * This hook is invoked from taxonomy_vocabulary_delete() before - * field_attach_delete_bundle() is called and before the vocabulary is actually - * removed from the database. + * This hook is invoked from entity_delete() before field_attach_delete_bundle() + * is called and before the vocabulary is actually removed from the database. * * @param Drupal\taxonomy\Vocabulary $vocabulary * The taxonomy vocabulary entity that is about to be deleted. * * @see hook_taxonomy_vocabulary_delete() - * @see taxonomy_vocabulary_delete() + * @see entity_delete() */ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Vocabulary $vocabulary) { if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { @@ -93,15 +92,14 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Vocabulary $vocabula /** * Respond to taxonomy vocabulary deletion. * - * This hook is invoked from taxonomy_vocabulary_delete() after - * field_attach_delete_bundle() has been called and after the vocabulary has - * been removed from the database. + * This hook is invoked from entity_delete() after field_attach_delete_bundle() + * has been called and after the vocabulary has been removed from the database. * * @param Drupal\taxonomy\Vocabulary $vocabulary * The taxonomy vocabulary entity that has been deleted. * * @see hook_taxonomy_vocabulary_predelete() - * @see taxonomy_vocabulary_delete() + * @see entity_delete() */ function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Vocabulary $vocabulary) { if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { @@ -113,7 +111,7 @@ function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Vocabulary $vocabulary) * Act on taxonomy terms when loaded. * * Modules implementing this hook can act on the term objects returned by - * taxonomy_term_load_multiple(). + * entity_load_multiple(). * * For performance reasons, information to be added to term objects should be * loaded in a single query for all terms where possible. @@ -196,14 +194,13 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { /** * Act before taxonomy term deletion. * - * This hook is invoked from taxonomy_term_delete() before - * field_attach_delete() is called and before the term is actually removed from - * the database. + * This hook is invoked from entity_delete() before field_attach_delete() is + * called and before the term is actually removed from the database. * * @param Drupal\taxonomy\Term $term * The taxonomy term entity that is about to be deleted. * - * @see taxonomy_term_delete() + * @see entity_delete() */ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { db_delete('term_synoynm')->condition('tid', $term->tid)->execute(); @@ -212,13 +209,13 @@ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { /** * Respond to taxonomy term deletion. * - * This hook is invoked from taxonomy_term_delete() after field_attach_delete() - * has been called and after the term has been removed from the database. + * This hook is invoked from entity_delete() after field_attach_delete() has + * been called and after the term has been removed from the database. * * @param Drupal\taxonomy\Term $term * The taxonomy term entity that has been deleted. * - * @see taxonomy_term_delete() + * @see entity_delete() */ function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { db_delete('term_synoynm')->condition('tid', $term->tid)->execute(); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index faa04dd..adf4363 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -90,7 +90,7 @@ function taxonomy_permission() { 'title' => t('Administer vocabularies and terms'), ), ); - foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { + foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { $permissions += array( 'edit terms in ' . $vocabulary->vid => array( 'title' => t('Edit terms in %vocabulary', array('%vocabulary' => $vocabulary->name)), @@ -434,37 +434,6 @@ function taxonomy_term_access($op, $term) { } /** - * Saves a vocabulary. - * - * @param Drupal\taxonomy\Vocabulary $vocabulary - * The taxonomy vocabulary entity to be saved. - */ -function taxonomy_vocabulary_save(Vocabulary $vocabulary) { - return $vocabulary->save(); -} - -/** - * Deletes a vocabulary. - * - * @param $vid - * A vocabulary ID. - * - */ -function taxonomy_vocabulary_delete($vid) { - taxonomy_vocabulary_delete_multiple(array($vid)); -} - -/** - * Deletes vocabularies. - * - * @param $vids - * The vocabulary ids. - */ -function taxonomy_vocabulary_delete_multiple(array $vids) { - entity_delete_multiple('taxonomy_vocabulary', $vids); -} - -/** * Implements hook_taxonomy_vocabulary_update(). */ function taxonomy_taxonomy_vocabulary_update(Vocabulary $vocabulary) { @@ -528,48 +497,13 @@ function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_te } if ($hierarchy != $vocabulary->hierarchy) { $vocabulary->hierarchy = $hierarchy; - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); } return $hierarchy; } /** - * Saves a term object to the database. - * - * @param Drupal\taxonomy\Term $term - * The taxonomy term entity to be saved. - * - * @return - * Status constant indicating whether term was inserted (SAVED_NEW) or updated - * (SAVED_UPDATED). When inserting a new term, $term->tid will contain the - * term ID of the newly created term. - */ -function taxonomy_term_save(Term $term) { - return $term->save(); -} - -/** - * Deletes a term. - * - * @param $tid - * The term ID. - */ -function taxonomy_term_delete($tid) { - taxonomy_term_delete_multiple(array($tid)); -} - -/** - * Deletes taxonomy terms. - * - * @param $tids - * The term ids to be deleted. - */ -function taxonomy_term_delete_multiple(array $tids) { - entity_delete_multiple('taxonomy_term', $tids); -} - -/** * Generates an array which displays a term detail page. * * @param Drupal\taxonomy\Term $term @@ -585,7 +519,7 @@ function taxonomy_term_show(Term $term) { * Constructs a drupal_render() style array from an array of loaded terms. * * @param array $terms - * An array of taxonomy terms as returned by taxonomy_term_load_multiple(). + * An array of taxonomy terms as returned by entity_load_multiple(). * @param string $view_mode * View mode, e.g. 'full', 'teaser'... * @param int $weight @@ -811,7 +745,7 @@ function taxonomy_term_load_parents($tid) { $query->orderBy('t.weight'); $query->orderBy('t.name'); $tids = $query->execute()->fetchCol(); - $parents[$tid] = taxonomy_term_load_multiple($tids); + $parents[$tid] = entity_load_multiple('taxonomy_term', $tids); } return isset($parents[$tid]) ? $parents[$tid] : array(); @@ -828,7 +762,7 @@ function taxonomy_term_load_parents_all($tid) { } $parents = array(); - if ($term = taxonomy_term_load($tid)) { + if ($term = entity_load('taxonomy_term', $tid)) { $parents[] = $term; $n = 0; while ($parent = taxonomy_term_load_parents($parents[$n]->tid)) { @@ -869,7 +803,7 @@ function taxonomy_term_load_children($tid, $vid = 0) { $query->orderBy('t.weight'); $query->orderBy('t.name'); $tids = $query->execute()->fetchCol(); - $children[$tid] = taxonomy_term_load_multiple($tids); + $children[$tid] = entity_load_multiple('taxonomy_term', $tids); } return isset($children[$tid]) ? $children[$tid] : array(); @@ -931,7 +865,7 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities // Load full entities, if necessary. The entity controller statically // caches the results. if ($load_entities) { - $term_entities = taxonomy_term_load_multiple(array_keys($terms[$vid])); + $term_entities = entity_load_multiple('taxonomy_term', array_keys($terms[$vid])); } $max_depth = (!isset($max_depth)) ? count($children[$vid]) : $max_depth; @@ -1023,46 +957,6 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { } /** - * Load multiple taxonomy terms based on certain conditions. - * - * This function should be used whenever you need to load more than one term - * from the database. Terms are loaded into memory and will not require - * database access if loaded again during the same page request. - * - * @see entity_load_multiple() - * @see Drupal\Core\Entity\EntityFieldQuery - * - * @param array $tids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * - * @return array - * An array of taxonomy term entities, indexed by tid. When no results are - * found, an empty array is returned. - */ -function taxonomy_term_load_multiple(array $tids = NULL) { - return entity_load_multiple('taxonomy_term', $tids); -} - -/** - * Loads multiple taxonomy vocabularies based on certain conditions. - * - * This function should be used whenever you need to load more than one - * vocabulary from the database. Terms are loaded into memory and will not - * require database access if loaded again during the same page request. - * - * @see entity_load_multiple() - * - * @param array $vids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * - * @return array - * An array of vocabulary objects, indexed by vid. - */ -function taxonomy_vocabulary_load_multiple(array $vids = NULL) { - return entity_load_multiple('taxonomy_vocabulary', $vids); -} - -/** * Return the taxonomy vocabulary entity matching a vocabulary ID. * * @param int $vid @@ -1073,6 +967,10 @@ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { * statically cached. * * @see taxonomy_vocabulary_machine_name_load() + * + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function taxonomy_vocabulary_load($vid) { return entity_load('taxonomy_vocabulary', $vid); @@ -1088,7 +986,7 @@ function taxonomy_vocabulary_load($vid) { * The taxonomy vocabulary entity, if exists, FALSE otherwise. Results are * statically cached. * - * @see taxonomy_vocabulary_load() + * @see entity_load_multiple_by_properties() */ function taxonomy_vocabulary_machine_name_load($name) { $result = entity_load_multiple_by_properties('taxonomy_vocabulary', array('machine_name' => $name)); @@ -1104,6 +1002,10 @@ function taxonomy_vocabulary_machine_name_load($name) { * @return Drupal\taxonomy\Term|false * A taxonomy term entity, or FALSE if the term was not found. Results are * statically cached. + * + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function taxonomy_term_load($tid) { if (!is_numeric($tid)) { @@ -1203,14 +1105,14 @@ function taxonomy_options_list($field, $instance, $entity_type, $entity) { */ function taxonomy_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { // Build an array of existing term IDs so they can be loaded with - // taxonomy_term_load_multiple(); + // entity_load_multiple(); foreach ($items as $delta => $item) { if (!empty($item['tid']) && $item['tid'] != 'autocreate') { $tids[] = $item['tid']; } } if (!empty($tids)) { - $terms = taxonomy_term_load_multiple($tids); + $terms = entity_load_multiple('taxonomy_term', $tids); // Check each existing item to ensure it can be found in the // allowed values for this field. @@ -1386,7 +1288,7 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field, } } if ($tids) { - $terms = taxonomy_term_load_multiple($tids); + $terms = entity_load_multiple('taxonomy_term', $tids); // Iterate through the fieldable entities again to attach the loaded term data. foreach ($entities as $id => $entity) { @@ -1448,7 +1350,7 @@ function taxonomy_autocomplete_validate($element, &$form_state) { */ function taxonomy_field_settings_form($field, $instance, $has_data) { // Get proper values for 'allowed_values_function', which is a core setting. - $vocabularies = taxonomy_vocabulary_load_multiple(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $options = array(); foreach ($vocabularies as $vocabulary) { $options[$vocabulary->machine_name] = $vocabulary->name; @@ -1550,7 +1452,7 @@ function taxonomy_field_presave($entity_type, $entity, $field, $instance, $langc unset($item['tid']); $term = entity_create('taxonomy_term', $item); $term->langcode = $langcode; - taxonomy_term_save($term); + $term->save(); $items[$delta]['tid'] = $term->tid; } } diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 7c77716..97eebce 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -47,7 +47,7 @@ function taxonomy_term_page(Term $term) { $build = taxonomy_term_show($term); if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) { - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); $build += node_view_multiple($nodes); $build['pager'] = array( '#theme' => 'pager', diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index c7847b3..fa789bc 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -123,7 +123,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'vocabulary': - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $term->vid); $replacements[$original] = check_plain($vocabulary->name); break; @@ -137,7 +137,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = } if ($vocabulary_tokens = token_find_with_prefix($tokens, 'vocabulary')) { - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = entity_load('taxonomy_vocabulary', $term->vid); $replacements += token_generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); } diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index 7cd99cc..ad7dd76 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -77,7 +77,7 @@ function testTrackerAll() { $this->assertLink(t('My recent content'), 0, t('User tab shows up on the global tracker page.')); // Delete a node and ensure it no longer appears on the tracker. - node_delete($published->nid); + entity_delete('node', $published->nid); $this->drupalGet('tracker'); $this->assertNoText($published->label(), t('Deleted node do not show up in the tracker listing.')); } diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index bf1e528..525e973 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -121,7 +121,7 @@ function translation_permission() { function translation_node_access($node, $op, $account, $langcode) { $request_has_translation_arg = isset($_GET['translation']) && isset($_GET['target']) && is_numeric($_GET['translation']); if ($op == 'create' && $request_has_translation_arg) { - $source_node = node_load($_GET['translation']); + $source_node = entity_load('node', $_GET['translation']); if (empty($source_node) || !translation_user_can_translate_node($source_node, $account)){ return NODE_ACCESS_DENY; } @@ -311,7 +311,7 @@ function translation_node_prepare(Node $node) { isset($_GET['target']) && is_numeric($_GET['translation'])) { - $source_node = node_load($_GET['translation']); + $source_node = entity_load('node', $_GET['translation']); $language_list = language_list(); $langcode = $_GET['target']; @@ -477,7 +477,7 @@ function translation_remove_from_set($node) { * Array of partial node objects (nid, title, langcode) representing all * nodes in the translation set, in effect all translations of node $tnid, * including node $tnid itself. Because these are partial nodes, you need to - * node_load() the full node, if you need more properties. The array is + * entity_load() the full node, if you need more properties. The array is * indexed by language code. */ function translation_node_get_translations($tnid) { @@ -523,7 +523,7 @@ function translation_supported_type($type) { function translation_path_get_translations($path) { $paths = array(); // Check for a node related path, and for its translations. - if ((preg_match("!^node/(\d+)(/.+|)$!", $path, $matches)) && ($node = node_load((int) $matches[1])) && !empty($node->tnid)) { + if ((preg_match("!^node/(\d+)(/.+|)$!", $path, $matches)) && ($node = entity_load('node', (int) $matches[1])) && !empty($node->tnid)) { foreach (translation_node_get_translations($node->tnid) as $language => $translation_node) { $paths[$language] = 'node/' . $translation_node->nid . $matches[2]; } @@ -540,7 +540,7 @@ function translation_language_switch_links_alter(array &$links, $type, $path) { $language_type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); if ($type == $language_type && preg_match("!^node/(\d+)(/.+|)!", $path, $matches)) { - $node = node_load((int) $matches[1]); + $node = entity_load('node', (int) $matches[1]); if (empty($node->tnid)) { // If the node cannot be found nothing needs to be done. If it does not diff --git a/core/modules/translation/translation.pages.inc b/core/modules/translation/translation.pages.inc index e33f53e..82c759c 100644 --- a/core/modules/translation/translation.pages.inc +++ b/core/modules/translation/translation.pages.inc @@ -41,7 +41,7 @@ function translation_node_overview(Node $node) { if (isset($translations[$langcode])) { // Existing translation in the translation set: display status. // We load the full node to check whether the user can edit it. - $translation_node = node_load($translations[$langcode]->nid); + $translation_node = entity_load('node', $translations[$langcode]->nid); $path = 'node/' . $translation_node->nid; $links = language_negotiation_get_switch_links($type, $path); $title = empty($links->links[$langcode]['href']) ? l($translation_node->label(), $path) : l($translation_node->label(), $links->links[$langcode]['href'], $links->links[$langcode]); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAdminTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAdminTest.php index 7589094..622f6ae 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAdminTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAdminTest.php @@ -70,13 +70,13 @@ function testUserAdmin() { $this->assertText($user_c->name, t('User C on filtered by role on admin users page')); // Test blocking of a user. - $account = user_load($user_c->uid); + $account = entity_load('user', $user_c->uid); $this->assertEqual($account->status, 1, 'User C not blocked'); $edit = array(); $edit['operation'] = 'block'; $edit['accounts[' . $account->uid . ']'] = TRUE; $this->drupalPost('admin/people', $edit, t('Update')); - $account = user_load($user_c->uid, TRUE); + $account = entity_load('user', $user_c->uid, TRUE); $this->assertEqual($account->status, 0, 'User C blocked'); // Test unblocking of a user from /admin/people page and sending of activation mail @@ -84,18 +84,18 @@ function testUserAdmin() { $editunblock['operation'] = 'unblock'; $editunblock['accounts[' . $account->uid . ']'] = TRUE; $this->drupalPost('admin/people', $editunblock, t('Update')); - $account = user_load($user_c->uid, TRUE); + $account = entity_load('user', $user_c->uid, TRUE); $this->assertEqual($account->status, 1, 'User C unblocked'); $this->assertMail("to", $account->mail, "Activation mail sent to user C"); // Test blocking and unblocking another user from /user/[uid]/edit form and sending of activation mail $user_d = $this->drupalCreateUser(array()); - $account1 = user_load($user_d->uid, TRUE); + $account1 = entity_load('user', $user_d->uid, TRUE); $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => 0), t('Save')); - $account1 = user_load($user_d->uid, TRUE); + $account1 = entity_load('user', $user_d->uid, TRUE); $this->assertEqual($account1->status, 0, 'User D blocked'); $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => TRUE), t('Save')); - $account1 = user_load($user_d->uid, TRUE); + $account1 = entity_load('user', $user_d->uid, TRUE); $this->assertEqual($account1->status, 1, 'User D unblocked'); $this->assertMail("to", $account1->mail, "Activation mail sent to user D"); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index 0d12cff..d93ce41 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -41,7 +41,7 @@ function testUserCancelWithoutPermission() { $account = $this->drupalCreateUser(array()); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); // Create a node. $node = $this->drupalCreateNode(array('uid' => $account->uid)); @@ -54,11 +54,11 @@ function testUserCancelWithoutPermission() { $timestamp = $account->login; $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); $this->assertResponse(403, t('Bogus cancelling request rejected.')); - $account = user_load($account->uid); + $account = entity_load('user', $account->uid); $this->assertTrue($account->status == 1, t('User account was not canceled.')); // Confirm user's content has not been altered. - $test_node = node_load($node->nid, TRUE); + $test_node = entity_load('node', $node->nid, TRUE); $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), t('Node of the user has not been altered.')); } @@ -84,7 +84,7 @@ function testUserCancelUid1() { ->execute(); // Reload and log in uid 1. - $user1 = user_load(1, TRUE); + $user1 = entity_load('user', 1, TRUE); $user1->pass_raw = $password; // Try to cancel uid 1's account with a different user. @@ -97,7 +97,7 @@ function testUserCancelUid1() { $this->drupalPost('admin/people', $edit, t('Update')); // Verify that uid 1's account was not cancelled. - $user1 = user_load(1, TRUE); + $user1 = entity_load('user', 1, TRUE); $this->assertEqual($user1->status, 1, t('User #1 still exists and is not blocked.')); } @@ -111,7 +111,7 @@ function testUserCancelInvalid() { $account = $this->drupalCreateUser(array('cancel account')); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); // Create a node. $node = $this->drupalCreateNode(array('uid' => $account->uid)); @@ -128,18 +128,18 @@ function testUserCancelInvalid() { $bogus_timestamp = $timestamp + 60; $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login)); $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), t('Bogus cancelling request rejected.')); - $account = user_load($account->uid); + $account = entity_load('user', $account->uid); $this->assertTrue($account->status == 1, t('User account was not canceled.')); // Attempt expired account cancellation request confirmation. $bogus_timestamp = $timestamp - 86400 - 60; $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login)); $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), t('Expired cancel account request rejected.')); - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->assertTrue($account->status, t('User account was not canceled.')); // Confirm user's content has not been altered. - $test_node = node_load($node->nid, TRUE); + $test_node = entity_load('node', $node->nid, TRUE); $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), t('Node of the user has not been altered.')); } @@ -154,7 +154,7 @@ function testUserBlock() { $this->drupalLogin($web_user); // Load real user object. - $account = user_load($web_user->uid, TRUE); + $account = entity_load('user', $web_user->uid, TRUE); // Attempt to cancel account. $this->drupalGet('user/' . $account->uid . '/edit'); @@ -171,7 +171,7 @@ function testUserBlock() { // Confirm account cancellation request. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->assertTrue($account->status == 0, t('User has been blocked.')); // Confirm user is logged out. @@ -188,7 +188,7 @@ function testUserBlockUnpublish() { $account = $this->drupalCreateUser(array('cancel account')); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); // Create a node with two revisions. $node = $this->drupalCreateNode(array('uid' => $account->uid)); @@ -209,11 +209,11 @@ function testUserBlockUnpublish() { // Confirm account cancellation request. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->assertTrue($account->status == 0, t('User has been blocked.')); // Confirm user's content has been unpublished. - $test_node = node_load($node->nid, TRUE); + $test_node = entity_load('node', $node->nid, TRUE); $this->assertTrue($test_node->status == 0, t('Node of the user has been unpublished.')); $test_node = node_revision_load($node->vid); $this->assertTrue($test_node->status == 0, t('Node revision of the user has been unpublished.')); @@ -232,7 +232,7 @@ function testUserAnonymize() { $account = $this->drupalCreateUser(array('cancel account')); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); // Create a simple node. $node = $this->drupalCreateNode(array('uid' => $account->uid)); @@ -259,14 +259,14 @@ function testUserAnonymize() { // Confirm account cancellation request. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); - $this->assertFalse(user_load($account->uid, TRUE), t('User is not found in the database.')); + $this->assertFalse(entity_load('user', $account->uid, TRUE), t('User is not found in the database.')); // Confirm that user's content has been attributed to anonymous user. - $test_node = node_load($node->nid, TRUE); + $test_node = entity_load('node', $node->nid, TRUE); $this->assertTrue(($test_node->uid == 0 && $test_node->status == 1), t('Node of the user has been attributed to anonymous user.')); $test_node = node_revision_load($revision, TRUE); $this->assertTrue(($test_node->revision_uid == 0 && $test_node->status == 1), t('Node revision of the user has been attributed to anonymous user.')); - $test_node = node_load($revision_node->nid, TRUE); + $test_node = entity_load('node', $revision_node->nid, TRUE); $this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), t("Current revision of the user's node was not attributed to anonymous user.")); // Confirm that user is logged out. @@ -283,7 +283,7 @@ function testUserDelete() { $account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval')); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); // Create a simple node. $node = $this->drupalCreateNode(array('uid' => $account->uid)); @@ -323,13 +323,13 @@ function testUserDelete() { // Confirm account cancellation request. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); - $this->assertFalse(user_load($account->uid, TRUE), t('User is not found in the database.')); + $this->assertFalse(entity_load('user', $account->uid, TRUE), t('User is not found in the database.')); // Confirm that user's content has been deleted. - $this->assertFalse(node_load($node->nid, TRUE), t('Node of the user has been deleted.')); + $this->assertFalse(entity_load('node', $node->nid, TRUE), t('Node of the user has been deleted.')); $this->assertFalse(node_revision_load($revision), t('Node revision of the user has been deleted.')); - $this->assertTrue(node_load($revision_node->nid, TRUE), t("Current revision of the user's node was not deleted.")); - $this->assertFalse(comment_load($comment->cid), t('Comment of the user has been deleted.')); + $this->assertTrue(entity_load('node', $revision_node->nid, TRUE), t("Current revision of the user's node was not deleted.")); + $this->assertFalse(entity_load('comment', $comment->cid), t('Comment of the user has been deleted.')); // Confirm that user is logged out. $this->assertNoText($account->name, t('Logged out.')); @@ -357,7 +357,7 @@ function testUserCancelByAdmin() { // Confirm deletion. $this->drupalPost(NULL, NULL, t('Cancel account')); $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), t('User deleted.')); - $this->assertFalse(user_load($account->uid), t('User is not found in the database.')); + $this->assertFalse(entity_load('user', $account->uid), t('User is not found in the database.')); } /** @@ -385,7 +385,7 @@ function testUserWithoutEmailCancelByAdmin() { // Confirm deletion. $this->drupalPost(NULL, NULL, t('Cancel account')); $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), t('User deleted.')); - $this->assertFalse(user_load($account->uid), t('User is not found in the database.')); + $this->assertFalse(entity_load('user', $account->uid), t('User is not found in the database.')); } /** @@ -427,17 +427,17 @@ function testMassUserCancelByAdmin() { $status = TRUE; foreach ($users as $account) { $status = $status && (strpos($this->content, t('%name has been deleted.', array('%name' => $account->name))) !== FALSE); - $status = $status && !user_load($account->uid, TRUE); + $status = $status && !entity_load('user', $account->uid, TRUE); } $this->assertTrue($status, t('Users deleted and not found in the database.')); // Ensure that admin account was not cancelled. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), t('Account cancellation request mailed message displayed.')); - $admin_user = user_load($admin_user->uid); + $admin_user = entity_load('user', $admin_user->uid); $this->assertTrue($admin_user->status == 1, t('Administrative user is found in the database and enabled.')); // Verify that uid 1's account was not cancelled. - $user1 = user_load(1, TRUE); + $user1 = entity_load('user', 1, TRUE); $this->assertEqual($user1->status, 1, t('User #1 still exists and is not blocked.')); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserDeleteTest.php b/core/modules/user/lib/Drupal/user/Tests/UserDeleteTest.php index 2b9442d..341673d 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserDeleteTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserDeleteTest.php @@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests user_delete() and user_delete_multiple() behavior. + * Tests entity_delete() and entity_delete_multiple() behavior. */ class UserDeleteTest extends WebTestBase { @@ -44,9 +44,9 @@ function testUserDeleteMultiple() { $this->assertTrue($roles_created > 0, 'Role assigments created for new users and deletion of role assigments can be tested'); // We should be able to load one of the users. - $this->assertTrue(user_load($user_a->uid), 'User is created and deltion of user can be tested'); + $this->assertTrue(entity_load('user', $user_a->uid), 'User is created and deltion of user can be tested'); // Delete the users. - user_delete_multiple($uids); + entity_delete_multiple('user', $uids); // Test if the roles assignments are deleted. $query = db_select('users_roles', 'r'); $roles_after_deletion = $query @@ -56,9 +56,9 @@ function testUserDeleteMultiple() { ->execute() ->fetchField(); $this->assertTrue($roles_after_deletion == 0, 'Role assigments deleted along with users'); - // Test if the users are deleted, user_load() will return FALSE. - $this->assertFalse(user_load($user_a->uid), format_string('User with id @uid deleted.', array('@uid' => $user_a->uid))); - $this->assertFalse(user_load($user_b->uid), format_string('User with id @uid deleted.', array('@uid' => $user_b->uid))); - $this->assertFalse(user_load($user_c->uid), format_string('User with id @uid deleted.', array('@uid' => $user_c->uid))); + // Test if the users are deleted, entity_load() will return FALSE. + $this->assertFalse(entity_load('user', $user_a->uid), format_string('User with id @uid deleted.', array('@uid' => $user_a->uid))); + $this->assertFalse(entity_load('user', $user_b->uid), format_string('User with id @uid deleted.', array('@uid' => $user_b->uid))); + $this->assertFalse(entity_load('user', $user_c->uid), format_string('User with id @uid deleted.', array('@uid' => $user_c->uid))); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php index 43cb43c..5ff5d30 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php @@ -112,14 +112,14 @@ function testPasswordRehashOnLogin() { $this->drupalLogin($account); $this->drupalLogout(); // Load the stored user. The password hash should reflect $count_log2. - $account = user_load($account->uid); + $account = entity_load('user', $account->uid); $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT); // Change $count_log2 and log in again. variable_set('password_count_log2', DRUPAL_HASH_COUNT + 1); $account->pass_raw = $password; $this->drupalLogin($account); // Load the stored user, which should have a different password hash now. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT + 1); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php index 96ac5de..699989d 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php @@ -49,7 +49,7 @@ function testUserPasswordResetExpired() { $account = $this->drupalCreateUser(); $this->drupalLogin($account); // Load real user object. - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); $this->drupalLogout(); // To attempt an expired password reset, create a password reset link as if diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index ddfae72..768be98 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -273,7 +273,7 @@ function testDeletePicture() { $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save')); // Load actual user data from database. - $account = user_load($this->user->uid, TRUE); + $account = entity_load('user', $this->user->uid, TRUE); $pic_path = !empty($account->picture) ? $account->picture->uri : NULL; // Check if image is displayed in user's profile page. @@ -287,10 +287,10 @@ function testDeletePicture() { $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save')); // Load actual user data from database. - $account1 = user_load($this->user->uid, TRUE); + $account1 = entity_load('user', $this->user->uid, TRUE); $this->assertFalse($account1->picture, 'User object has no picture'); - $file = file_load($account->picture->fid); + $file = entity_load('file', $account->picture->fid); $this->assertFalse($file, 'File is removed from database'); // Clear out PHP's file stat cache so we see the current value. @@ -303,7 +303,7 @@ function saveUserPicture($image) { $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save')); // Load actual user data from database. - $account = user_load($this->user->uid, TRUE); + $account = entity_load('user', $this->user->uid, TRUE); return !empty($account->picture) ? $account->picture->uri : NULL; } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php index eaabdd2..82dafa6 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php @@ -92,7 +92,7 @@ function testCreateUserWithRole() { * Defaults to TRUE. */ private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) { - $account = user_load($account->uid, TRUE); + $account = entity_load('user', $account->uid, TRUE); if ($is_assigned) { $this->assertTrue(array_key_exists($rid, $account->roles), t('The role is present in the user object.')); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSaveTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSaveTest.php index 655651f..272d271 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserSaveTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserSaveTest.php @@ -43,7 +43,7 @@ function testUserImport() { $user->save(); // Test if created user exists. - $user_by_uid = user_load($test_uid); + $user_by_uid = entity_load('user', $test_uid); $this->assertTrue($user_by_uid, t('Loading user by uid.')); $user_by_name = user_load_by_name($test_name); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php index 3daa476..84cd531 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php @@ -55,8 +55,8 @@ function testUserTokenReplacement() { $this->drupalLogout(); $this->drupalLogin($user2); - $account = user_load($user1->uid); - $global_account = user_load($GLOBALS['user']->uid); + $account = entity_load('user', $user1->uid); + $global_account = entity_load('user', $GLOBALS['user']->uid); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 2660300..c3e63ce 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -47,7 +47,7 @@ function attachLoad(&$queried_users, $load_revision = FALSE) { // Add the full file objects for user pictures if enabled. if (!empty($picture_fids) && variable_get('user_pictures', 1) == 1) { - $pictures = file_load_multiple($picture_fids); + $pictures = entity_load_multiple('file', $picture_fids); foreach ($queried_users as $entity) { if (!empty($entity->picture) && isset($pictures[$entity->picture])) { $entity->picture = $pictures[$entity->picture]; @@ -106,7 +106,7 @@ protected function preSave(EntityInterface $entity) { elseif (!empty($entity->picture_delete)) { $entity->picture = 0; file_usage_delete($entity->original->picture, 'user', 'user', $entity->uid); - file_delete($entity->original->picture->fid); + entity_delete('file', $entity->original->picture->fid); } if (!$entity->isNew()) { @@ -132,7 +132,7 @@ protected function preSave(EntityInterface $entity) { // Delete the previous picture if it was deleted or replaced. if (!empty($entity->original->picture->fid)) { file_usage_delete($entity->original->picture, 'user', 'user', $entity->uid); - file_delete($entity->original->picture->fid); + entity_delete('file', $entity->original->picture->fid); } } $entity->picture = empty($entity->picture->fid) ? 0 : $entity->picture->fid; diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 0c3002c..a9b2daf 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -15,14 +15,14 @@ /** * Act on user objects when loaded from the database. * - * Due to the static cache in user_load_multiple() you should not use this + * Due to the static cache in entity_load_multiple() you should not use this * hook to modify the user properties returned by the {users} table itself * since this may result in unreliable results when loading from cache. * * @param $users * An array of user objects, indexed by uid. * - * @see user_load_multiple() + * @see entity_load_multiple() * @see profile_user_load() */ function hook_user_load($users) { @@ -35,7 +35,7 @@ function hook_user_load($users) { /** * Act before user deletion. * - * This hook is invoked from user_delete_multiple() before + * This hook is invoked from entity_delete_multiple() before * field_attach_delete() is called and before the user is actually removed from * the database. * @@ -46,7 +46,7 @@ function hook_user_load($users) { * The account that is about to be deleted. * * @see hook_user_delete() - * @see user_delete_multiple() + * @see entity_delete_multiple() */ function hook_user_predelete($account) { db_delete('mytable') @@ -57,7 +57,7 @@ function hook_user_predelete($account) { /** * Respond to user deletion. * - * This hook is invoked from user_delete_multiple() after field_attach_delete() + * This hook is invoked from entity_delete_multiple() after field_attach_delete() * has been called and after the user has been removed from the database. * * Modules should additionally implement hook_user_cancel() to process stored @@ -67,7 +67,7 @@ function hook_user_predelete($account) { * The account that has been deleted. * * @see hook_user_predelete() - * @see user_delete_multiple() + * @see entity_delete_multiple() */ function hook_user_delete($account) { drupal_set_message(t('User: @name has been deleted.', array('@name' => $account->name))); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index a099f6b..6b9cc4a 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -138,7 +138,7 @@ function user_schema() { 'not null' => FALSE, 'size' => 'big', 'serialize' => TRUE, - 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.', + 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during entity_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.', ), ), 'indexes' => array( diff --git a/core/modules/user/user.module b/core/modules/user/user.module index e42002b..3c24452 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -262,7 +262,7 @@ function user_external_load($authname) { $uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchField(); if ($uid) { - return user_load($uid); + return entity_load('user', $uid); } else { return FALSE; @@ -270,32 +270,6 @@ function user_external_load($authname) { } /** - * Loads multiple users based on certain conditions. - * - * This function should be used whenever you need to load more than one user - * from the database. Users are loaded into memory and will not require - * database access if loaded again during the same page request. - * - * @param array $uids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. Use this if - * loading a user object which has been altered during the page request. - * - * @return array - * An array of user objects, indexed by uid. - * - * @see entity_load_multiple() - * @see user_load() - * @see user_load_by_mail() - * @see user_load_by_name() - * @see Drupal\Core\Entity\EntityFieldQuery - */ -function user_load_multiple(array $uids = NULL, $reset = FALSE) { - return entity_load_multiple('user', $uids, $reset); -} - -/** * Loads a user object. * * Drupal has a global $user object, which represents the currently-logged-in @@ -317,7 +291,9 @@ function user_load_multiple(array $uids = NULL, $reset = FALSE) { * A fully-loaded user object upon successful user load, or FALSE if the user * cannot be loaded. * - * @see user_load_multiple() + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function user_load($uid, $reset = FALSE) { return entity_load('user', $uid, $reset); @@ -332,7 +308,7 @@ function user_load($uid, $reset = FALSE) { * A fully-loaded $user object upon successful user load or FALSE if user * cannot be loaded. * - * @see user_load_multiple() + * @see entity_load_multiple_by_properties() */ function user_load_by_mail($mail) { $users = entity_load_multiple_by_properties('user', array('mail' => $mail)); @@ -348,7 +324,7 @@ function user_load_by_mail($mail) { * A fully-loaded $user object upon successful user load or FALSE if user * cannot be loaded. * - * @see user_load_multiple() + * @see entity_load_multiple_by_properties() */ function user_load_by_name($name) { $users = entity_load_multiple_by_properties('user', array('name' => $name)); @@ -662,7 +638,7 @@ function user_search_execute($keys = NULL, $conditions = NULL) { ->limit(15) ->execute() ->fetchCol(); - $accounts = user_load_multiple($uids); + $accounts = entity_load_multiple('user', $uids); $results = array(); foreach ($accounts as $account) { @@ -957,7 +933,7 @@ function template_preprocess_user_picture(&$variables) { // comment_load_multiple() functions the user module will be able to load // the picture files in mass during the object's load process. if (is_numeric($account->picture)) { - $account->picture = file_load($account->picture); + $account->picture = entity_load('file', $account->picture); } if (!empty($account->picture->uri)) { $filepath = $account->picture->uri; @@ -1130,7 +1106,7 @@ function user_view_access($account) { elseif (user_access('access user profiles')) { // At this point, load the complete account object. if (!is_object($account)) { - $account = user_load($uid); + $account = entity_load('user', $uid); } return (is_object($account) && $account->status); } @@ -1471,14 +1447,14 @@ function user_uid_only_optional_to_arg($arg) { * A fully-loaded $user object upon successful user load, FALSE if user * cannot be loaded. * - * @see user_load() + * @see entity_load() * @todo rethink the naming of this in Drupal 8. */ function user_uid_optional_load($uid = NULL) { if (!isset($uid)) { $uid = $GLOBALS['user']->uid; } - return user_load($uid); + return entity_load('user', $uid); } /** @@ -1788,7 +1764,7 @@ function user_login_finalize(&$edit = array()) { */ function user_login_submit($form, &$form_state) { global $user; - $user = user_load($form_state['uid']); + $user = entity_load('user', $form_state['uid']); $form_state['redirect'] = 'user/' . $user->uid; user_login_finalize($form_state); @@ -1917,7 +1893,7 @@ function user_pass_rehash($password, $timestamp, $login) { function user_cancel($edit, $uid, $method) { global $user; - $account = user_load($uid); + $account = entity_load('user', $uid); if (!$account) { drupal_set_message(t('The user account %id does not exist.', array('%id' => $uid)), 'error'); @@ -1932,7 +1908,7 @@ function user_cancel($edit, $uid, $method) { ); batch_set($batch); - // When the 'user_cancel_delete' method is used, user_delete() is called, + // When the 'user_cancel_delete' method is used, entity_delete() is called, // which invokes hook_user_predelete() and hook_user_delete(). Modules // should use those hooks to respond to the account deletion. if ($method != 'user_cancel_delete') { @@ -1984,7 +1960,7 @@ function _user_cancel($edit, $account, $method) { if (!empty($edit['user_cancel_notify'])) { _user_mail_notify('status_canceled', $account); } - user_delete($account->uid); + entity_delete('user', $account->uid); drupal_set_message(t('%name has been deleted.', array('%name' => $account->name))); watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE); break; @@ -2001,29 +1977,6 @@ function _user_cancel($edit, $account, $method) { } /** - * Delete a user. - * - * @param $uid - * A user ID. - */ -function user_delete($uid) { - user_delete_multiple(array($uid)); -} - -/** - * Delete multiple user accounts. - * - * @param $uids - * An array of user IDs. - * - * @see hook_user_predelete() - * @see hook_user_delete() - */ -function user_delete_multiple(array $uids) { - entity_get_controller('user')->delete($uids); -} - -/** * Page callback wrapper for user_view(). */ function user_view_page($account) { @@ -2515,7 +2468,7 @@ function user_user_operations($form = array(), $form_state = array()) { * Callback function for admin mass unblocking users. */ function user_user_operations_unblock($accounts) { - $accounts = user_load_multiple($accounts); + $accounts = entity_load_multiple('user', $accounts); foreach ($accounts as $account) { // Skip unblocking user if they are already unblocked. if ($account !== FALSE && $account->status == 0) { @@ -2529,7 +2482,7 @@ function user_user_operations_unblock($accounts) { * Callback function for admin mass blocking users. */ function user_user_operations_block($accounts) { - $accounts = user_load_multiple($accounts); + $accounts = entity_load_multiple('user', $accounts); foreach ($accounts as $account) { // Skip blocking user if they are already blocked. if ($account !== FALSE && $account->status == 1) { @@ -2550,7 +2503,7 @@ function user_multiple_role_edit($accounts, $operation, $rid) { switch ($operation) { case 'add_role': - $accounts = user_load_multiple($accounts); + $accounts = entity_load_multiple('user', $accounts); foreach ($accounts as $account) { // Skip adding the role to the user if they already have it. if ($account !== FALSE && !isset($account->roles[$rid])) { @@ -2564,7 +2517,7 @@ function user_multiple_role_edit($accounts, $operation, $rid) { } break; case 'remove_role': - $accounts = user_load_multiple($accounts); + $accounts = entity_load_multiple('user', $accounts); foreach ($accounts as $account) { // Skip removing the role from the user if they already don't have it. if ($account !== FALSE && isset($account->roles[$rid])) { @@ -2584,7 +2537,7 @@ function user_multiple_cancel_confirm($form, &$form_state) { $edit = $form_state['input']; $form['accounts'] = array('#prefix' => '