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' => '
  • ', '#suffix' => check_plain($subject) . '
  • '); @@ -244,7 +244,7 @@ function comment_multiple_delete_confirm($form, &$form_state) { */ function comment_multiple_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - comment_delete_multiple(array_keys($form_state['values']['comments'])); + entity_delete_multiple('comment', array_keys($form_state['values']['comments'])); cache_invalidate(array('content' => TRUE)); $count = count($form_state['values']['comments']); watchdog('content', 'Deleted @count comments.', array('@count' => $count)); @@ -263,7 +263,7 @@ function comment_multiple_delete_confirm_submit($form, &$form_state) { * @see comment_confirm_delete() */ function comment_confirm_delete_page($cid) { - if ($comment = comment_load($cid)) { + if ($comment = entity_load('comment', $cid)) { return drupal_get_form('comment_confirm_delete', $comment); } throw new NotFoundHttpException(); @@ -300,7 +300,7 @@ function comment_confirm_delete($form, &$form_state, Comment $comment) { function comment_confirm_delete_submit($form, &$form_state) { $comment = $form_state['comment']; // Delete the comment and its replies. - comment_delete($comment->cid); + entity_delete('comment', $comment->cid); drupal_set_message(t('The comment and all its replies have been deleted.')); watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $comment->cid)); // Clear the cache so an anonymous user sees that his comment was deleted. diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index 95c3e1d..d5f1a5c 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -133,7 +133,7 @@ function hook_comment_unpublish(Drupal\comment\Comment $comment) { /** * Act before comment deletion. * - * This hook is invoked from comment_delete_multiple() before + * This hook is invoked from entity_delete_multiple() before * field_attach_delete() is called and before the comment is actually removed * from the database. * @@ -141,7 +141,6 @@ function hook_comment_unpublish(Drupal\comment\Comment $comment) { * The comment object for the comment that is about to be deleted. * * @see hook_comment_delete() - * @see comment_delete_multiple() * @see entity_delete_multiple() */ function hook_comment_predelete(Drupal\comment\Comment $comment) { @@ -154,7 +153,7 @@ function hook_comment_predelete(Drupal\comment\Comment $comment) { /** * Respond to comment deletion. * - * This hook is invoked from comment_delete_multiple() after + * This hook is invoked from entity_delete_multiple() after * field_attach_delete() has called and after the comment has been removed from * the database. * @@ -162,7 +161,6 @@ function hook_comment_predelete(Drupal\comment\Comment $comment) { * The comment object for the comment that has been deleted. * * @see hook_comment_predelete() - * @see comment_delete_multiple() * @see entity_delete_multiple() */ function hook_comment_delete(Drupal\comment\Comment $comment) { diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 27ff7c3..f53cbec 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -504,7 +504,7 @@ function comment_block_view($delta = '') { * The comment listing set to the page on which the comment appears. */ function comment_permalink($cid) { - if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) { + if (($comment = entity_load('comment', $cid)) && ($node = entity_load('node', $comment->nid))) { // Find the current display page for this comment. $page = comment_get_display_page($comment->cid, $node->type); @@ -766,7 +766,7 @@ function comment_node_page_additions(Node $node) { $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED); $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); if ($cids = comment_get_thread($node, $mode, $comments_per_page)) { - $comments = comment_load_multiple($cids); + $comments = entity_load_multiple('comment', $cids); comment_prepare_thread($comments); $build = comment_view_multiple($comments, $node); $build['pager']['#theme'] = 'pager'; @@ -1145,7 +1145,7 @@ function comment_links(Comment $comment, Node $node) { * Constructs render array from an array of loaded comments. * * @param $comments - * An array of comments as returned by comment_load_multiple(). + * An array of comments as returned by entity_load_multiple(). * @param Drupal\node\Node $node * The node the comments are attached to. * @param $view_mode @@ -1374,7 +1374,7 @@ function comment_node_insert(Node $node) { */ function comment_node_predelete(Node $node) { $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->nid))->fetchCol(); - comment_delete_multiple($cids); + entity_delete_multiple('comment', $cids); db_delete('node_comment_statistics') ->condition('nid', $node->nid) ->execute(); @@ -1409,7 +1409,7 @@ function comment_node_update_index(Node $node, $langcode) { $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED); $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) { - $comments = comment_load_multiple($cids); + $comments = entity_load_multiple('comment', $cids); comment_prepare_thread($comments); $build = comment_view_multiple($comments, $node, $langcode); return drupal_render($build); @@ -1453,7 +1453,7 @@ function comment_user_cancel($edit, $account, $method) { $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid)); foreach ($comments as $comment) { $comment->status = 0; - comment_save($comment); + $comment->save(); } break; @@ -1461,7 +1461,7 @@ function comment_user_cancel($edit, $account, $method) { $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid)); foreach ($comments as $comment) { $comment->uid = 0; - comment_save($comment); + $comment->save(); } break; } @@ -1472,7 +1472,7 @@ function comment_user_cancel($edit, $account, $method) { */ function comment_user_predelete($account) { $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); - comment_delete_multiple($cids); + entity_delete_multiple('comment', $cids); } /** @@ -1500,58 +1500,6 @@ function comment_access($op, Comment $comment) { } /** - * Accepts a submission of new or changed comment content. - * - * @param Drupal\comment\Comment $comment - * A comment object. - */ -function comment_save(Comment $comment) { - $comment->save(); -} - -/** - * Deletes a comment and all its replies. - * - * @param $cid - * The ID of the comment to delete. - */ -function comment_delete($cid) { - comment_delete_multiple(array($cid)); -} - -/** - * Deletes comments and all their replies. - * - * @param $cids - * The IDs of the comments to delete. - * - * @see hook_comment_predelete() - * @see hook_comment_delete() - */ -function comment_delete_multiple($cids) { - entity_delete_multiple('comment', $cids); -} - -/** - * Loads comment entities from the database. - * - * @param array $cids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * Whether to reset the internal static entity cache. Note that the static - * cache is disabled in comment_entity_info() by default. - * - * @return array - * An array of comment objects, indexed by comment ID. - * - * @see entity_load() - * @see Drupal\Core\Entity\EntityFieldQuery - */ -function comment_load_multiple(array $cids = NULL, $reset = FALSE) { - return entity_load_multiple('comment', $cids, $reset); -} - -/** * Loads the entire comment by comment ID. * * @param int $cid @@ -1562,9 +1510,13 @@ function comment_load_multiple(array $cids = NULL, $reset = FALSE) { * * @return * The comment object. + * + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function comment_load($cid, $reset = FALSE) { - return entity_load('comment', $cid); + return entity_load('comment', $cid, $reset); } /** @@ -1687,7 +1639,7 @@ function comment_edit_page(Comment $comment) { function comment_preview(Comment $comment) { global $user; $preview_build = array(); - $node = node_load($comment->nid); + $node = entity_load('node', $comment->nid); if (!form_get_errors()) { $comment_body = field_get_items('comment', $comment, 'comment_body'); @@ -1722,7 +1674,7 @@ function comment_preview(Comment $comment) { if ($comment->pid) { $build = array(); - $comment = comment_load($comment->pid); + $comment = entity_load('comment', $comment->pid); if ($comment && $comment->status == COMMENT_PUBLISHED) { $build = comment_view($comment, $node); } @@ -2067,7 +2019,7 @@ function comment_unpublish_by_keyword_action_submit($form, $form_state) { * @ingroup actions */ function comment_save_action(Comment $comment) { - comment_save($comment); + $comment->save(); cache_invalidate(array('content' => TRUE)); watchdog('action', 'Saved comment %title', array('%title' => $comment->subject)); } @@ -2140,7 +2092,7 @@ function comment_rdf_mapping() { function comment_file_download_access($field, EntityInterface $entity, File $file) { if ($entity->entityType() == 'comment') { if (user_access('access comments') && $entity->status == COMMENT_PUBLISHED || user_access('administer comments')) { - $node = node_load($entity->nid); + $node = entity_load('node', $entity->nid); return node_access('view', $node); } return FALSE; diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index ed91d23..5d7d8f1 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -55,7 +55,7 @@ function comment_reply(Node $node, $pid = NULL) { if ($pid) { if (user_access('access comments')) { // Load the parent comment. - $comment = comment_load($pid); + $comment = entity_load('comment', $pid); if ($comment->status == COMMENT_PUBLISHED) { // If that comment exists, make sure that the current comment and the // parent comment both belong to the same parent node. @@ -119,9 +119,9 @@ function comment_approve($cid) { throw new AccessDeniedHttpException(); } - if ($comment = comment_load($cid)) { + if ($comment = entity_load('comment', $cid)) { $comment->status = COMMENT_PUBLISHED; - comment_save($comment); + $comment->save(); drupal_set_message(t('Comment approved.')); drupal_goto('node/' . $comment->nid); diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index c77cb67..a6895c3 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -137,7 +137,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = case 'mail': if ($comment->uid != 0) { - $account = user_load($comment->uid); + $account = entity_load('user', $comment->uid); $mail = $account->mail; } else { @@ -180,7 +180,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = case 'parent': if (!empty($comment->pid)) { - $parent = comment_load($comment->pid); + $parent = entity_load('comment', $comment->pid); $replacements[$original] = $sanitize ? filter_xss($parent->subject) : $parent->subject; } break; @@ -194,7 +194,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'node': - $node = node_load($comment->nid); + $node = entity_load('node', $comment->nid); $title = $node->label(); $replacements[$original] = $sanitize ? filter_xss($title) : $title; break; @@ -203,7 +203,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = // Chained token relationships. if ($node_tokens = token_find_with_prefix($tokens, 'node')) { - $node = node_load($comment->nid); + $node = entity_load('node', $comment->nid); $replacements += token_generate('node', $node_tokens, array('node' => $node), $options); } @@ -215,11 +215,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements += token_generate('date', $date_tokens, array('date' => $comment->changed), $options); } - if (($parent_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = comment_load($comment->pid)) { + if (($parent_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = entity_load('comment', $comment->pid)) { $replacements += token_generate('comment', $parent_tokens, array('comment' => $parent), $options); } - if (($author_tokens = token_find_with_prefix($tokens, 'author')) && $account = user_load($comment->uid)) { + if (($author_tokens = token_find_with_prefix($tokens, 'author')) && $account = entity_load('user', $comment->uid)) { $replacements += token_generate('user', $author_tokens, array('user' => $account), $options); } } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index cead0cd..244b166 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -21,7 +21,7 @@ class CommentFormController extends EntityFormController { public function form(array $form, array &$form_state, EntityInterface $comment) { global $user; - $node = node_load($comment->nid); + $node = entity_load('node', $comment->nid); $form_state['comment']['node'] = $node; // Use #comment-form as unique jump target, regardless of node type. @@ -332,7 +332,7 @@ public function preview(array $form, array &$form_state) { * Overrides Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { - $node = node_load($form_state['values']['nid']); + $node = entity_load('node', $form_state['values']['nid']); $comment = $this->getEntity($form_state); if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { @@ -341,7 +341,7 @@ public function save(array $form, array &$form_state) { user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); } - comment_save($comment); + $comment->save(); $form_state['values']['cid'] = $comment->cid; // Add an entry to the watchdog log. diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 4d447a5..9f52326 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -66,7 +66,7 @@ protected function preSave(EntityInterface $comment) { } // Make sure we have a proper bundle name. if (!isset($comment->node_type)) { - $node = node_load($comment->nid); + $node = entity_load('node', $comment->nid); $comment->node_type = 'comment_node_' . $node->type; } if (!$comment->cid) { @@ -98,7 +98,7 @@ protected function preSave(EntityInterface $comment) { // the thread value at the proper depth. // Get the parent comment: - $parent = comment_load($comment->pid); + $parent = entity_load('comment', $comment->pid); // Strip the "/" from the end of the parent thread. $parent->thread = (string) rtrim((string) $parent->thread, '/'); $prefix = $parent->thread . '.'; @@ -169,7 +169,7 @@ protected function postDelete($comments) { ->fields('c', array('cid')) ->condition('pid', array(array_keys($comments)), 'IN'); $child_cids = $query->execute()->fetchCol(); - comment_delete_multiple($child_cids); + entity_delete_multiple('comment', $child_cids); foreach ($comments as $comment) { $this->updateNodeStatistics($comment->nid); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php index 3190e8b..f46f989 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -27,7 +27,7 @@ function testCommentPublishUnpublishActions() { $comment_text = $this->randomName(); $subject = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $subject); - $comment = comment_load($comment->id); + $comment = entity_load('comment', $comment->id); // Unpublish a comment (direct form: doesn't actually save the comment). comment_unpublish_action($comment); @@ -37,7 +37,7 @@ function testCommentPublishUnpublishActions() { // Unpublish a comment (indirect form: modify the comment in the database). comment_unpublish_action(NULL, array('cid' => $comment->cid)); - $this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished'); + $this->assertEqual(entity_load('comment', $comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished'); $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), 'Found watchdog message'); // Publish a comment (direct form: doesn't actually save the comment). @@ -48,7 +48,7 @@ function testCommentPublishUnpublishActions() { // Publish a comment (indirect form: modify the comment in the database). comment_publish_action(NULL, array('cid' => $comment->cid)); - $this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, 'Comment was published'); + $this->assertEqual(entity_load('comment', $comment->cid)->status, COMMENT_PUBLISHED, 'Comment was published'); $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), 'Found watchdog message'); $this->clearWatchdog(); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php index 980efc7..d799395 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php @@ -34,7 +34,7 @@ function testCommentRebuild() { $subject_text = $this->randomName(); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Add the property to the content array and then see if it still exists on build. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index a2e5dfd..c01b834 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -33,7 +33,7 @@ function testCommentInterface() { $this->drupalLogin($this->web_user); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Set comments to have subject and preview to required. @@ -48,7 +48,7 @@ function testCommentInterface() { $subject_text = $this->randomName(); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Check comment display. @@ -65,7 +65,7 @@ function testCommentInterface() { // Test changing the comment author to "Anonymous". $this->drupalGet('comment/' . $comment->id . '/edit'); $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => '')); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, 'Comment author successfully changed to anonymous.'); // Test changing the comment author to an unverified user. @@ -78,7 +78,7 @@ function testCommentInterface() { // Test changing the comment author to a verified user. $this->drupalGet('comment/' . $comment->id . '/edit'); $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name)); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, 'Comment author successfully changed to a registered user.'); $this->drupalLogout(); @@ -90,7 +90,7 @@ function testCommentInterface() { $this->assertText($subject_text, 'Individual comment-reply subject found.'); $this->assertText($comment_text, 'Individual comment-reply body found.'); $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.'); $this->assertEqual($comment->id, $reply_loaded->pid, 'Pid of a reply to a comment is set correctly.'); $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, 'Thread of reply grows correctly.'); @@ -100,7 +100,7 @@ function testCommentInterface() { $this->assertText($subject_text, 'Individual comment-reply subject found.'); $this->assertText($comment_text, 'Individual comment-reply body found.'); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.'); $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, 'Thread of second reply grows correctly.'); @@ -204,7 +204,7 @@ public function testCommentNewCommentsIndicator() { 'langcode' => LANGUAGE_NOT_SPECIFIED, 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), )); - comment_save($comment); + $comment->save(); $this->drupalLogout(); // Log in with 'web user' and check comment links. @@ -251,7 +251,7 @@ function testCommentClasses() { 'language' => LANGUAGE_NOT_SPECIFIED, 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), )); - comment_save($comment); + $comment->save(); // Adjust the current/viewing user. switch ($case['user']) { @@ -349,7 +349,7 @@ function testCommentNodeCommentStatistics() { $this->web_user2 = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments')); // Checks the initial values of node comment statistics with no comment. - $node = node_load($this->node->nid); + $node = entity_load('node', $this->node->nid); $this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.'); $this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.'); $this->assertEqual($node->last_comment_uid, $this->web_user->uid, 'The initial value of node last_comment_uid is the node uid.'); @@ -359,11 +359,11 @@ function testCommentNodeCommentStatistics() { $this->drupalLogin($this->web_user2); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); // Checks the new values of node comment statistics with comment #1. - // The node needs to be reloaded with a node_load_multiple cache reset. - $node = node_load($this->node->nid, TRUE); + // The node needs to be reloaded with a entity_load_multiple cache reset. + $node = entity_load('node', $this->node->nid, TRUE); $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is NULL.'); $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is the comment #1 uid.'); $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is 1.'); @@ -383,12 +383,12 @@ function testCommentNodeCommentStatistics() { // Post comment #2 as anonymous (comment approval enabled). $this->drupalGet('comment/reply/' . $this->node->nid); $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', TRUE); - $comment_unpublished_loaded = comment_load($anonymous_comment->id); + $comment_unpublished_loaded = entity_load('comment', $anonymous_comment->id); // Checks the new values of node comment statistics with comment #2 and // ensure they haven't changed since the comment has not been moderated. - // The node needs to be reloaded with a node_load_multiple cache reset. - $node = node_load($this->node->nid, TRUE); + // The node needs to be reloaded with a entity_load_multiple cache reset. + $node = entity_load('node', $this->node->nid, TRUE); $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.'); $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is still the comment #1 uid.'); $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is still 1.'); @@ -405,11 +405,11 @@ function testCommentNodeCommentStatistics() { // Post comment #3 as anonymous. $this->drupalGet('comment/reply/' . $this->node->nid); $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', array('name' => $this->randomName())); - $comment_loaded = comment_load($anonymous_comment->id); + $comment_loaded = entity_load('comment', $anonymous_comment->id); // Checks the new values of node comment statistics with comment #3. - // The node needs to be reloaded with a node_load_multiple cache reset. - $node = node_load($this->node->nid, TRUE); + // The node needs to be reloaded with a entity_load_multiple cache reset. + $node = entity_load('node', $this->node->nid, TRUE); $this->assertEqual($node->last_comment_name, $comment_loaded->name, 'The value of node last_comment_name is the name of the anonymous user.'); $this->assertEqual($node->last_comment_uid, 0, 'The value of node last_comment_uid is zero.'); $this->assertEqual($node->comment_count, 2, 'The value of node comment_count is 2.'); @@ -533,7 +533,7 @@ function setEnvironment(array $info) { 'langcode' => LANGUAGE_NOT_SPECIFIED, 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), )); - comment_save($comment); + $comment->save(); $this->comment = $comment; // comment_num_new() relies on node_last_viewed(), so ensure that no one @@ -542,7 +542,7 @@ function setEnvironment(array $info) { } else { $cids = db_query("SELECT cid FROM {comment}")->fetchCol(); - comment_delete_multiple($cids); + entity_delete_multiple('comment', $cids); unset($this->comment); } } @@ -552,7 +552,7 @@ function setEnvironment(array $info) { variable_set('comment_anonymous_' . $this->node->type, $info['contact']); if ($this->node->comment != $info['comments']) { $this->node->comment = $info['comments']; - node_save($this->node); + $this->node->save(); } // Change user settings. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 9c3af8e..6abcc88 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -121,7 +121,7 @@ function testCommentLanguage() { ->range(0, 1) ->execute() ->fetchField(); - $comment = comment_load($cid); + $comment = entity_load('comment', $cid); $args = array('%node_language' => $node_langcode, '%comment_language' => $comment->langcode, '%langcode' => $langcode); $this->assertEqual($comment->langcode, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args)); $this->assertEqual($comment->comment_body[$langcode][0]['value'], $comment_values[$node_langcode][$langcode], 'Comment body correctly stored.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php index d357bd0..1503f74 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php @@ -60,7 +60,7 @@ function testThreadedCommentView() { $comment_text = $this->randomName(); $comment_subject = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $comment_subject); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Check comment display. @@ -73,7 +73,7 @@ function testThreadedCommentView() { $reply_text = $this->randomName(); $reply_subject = $this->randomName(); $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.'); // Go to the node page and verify comment and reply are visible. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php index b517d04..0e11b15 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php @@ -26,8 +26,8 @@ public static function getInfo() { function testNodeDeletion() { $this->drupalLogin($this->web_user); $comment = $this->postComment($this->node, $this->randomName(), $this->randomName()); - $this->assertTrue(comment_load($comment->id), 'The comment could be loaded.'); - node_delete($this->node->nid); - $this->assertFalse(comment_load($comment->id), 'The comment could not be loaded after the node was deleted.'); + $this->assertTrue(entity_load('comment', $comment->id), 'The comment could be loaded.'); + entity_delete('node', $this->node->nid); + $this->assertFalse(entity_load('comment', $comment->id), 'The comment could not be loaded after the node was deleted.'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php index 52f1e32..2fc6895 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php @@ -245,7 +245,7 @@ function testCommentNewPageIndicator() { 6 => 0, // Page of comment 0 ); - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); foreach ($expected_pages as $new_replies => $expected_page) { $returned = comment_new_page_count($node->comment_count, $new_replies, $node); $returned_page = is_array($returned) ? $returned['page'] : 0; @@ -263,7 +263,7 @@ function testCommentNewPageIndicator() { 6 => 0, // Page of comment 0 ); - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); foreach ($expected_pages as $new_replies => $expected_page) { $returned = comment_new_page_count($node->comment_count, $new_replies, $node); $returned_page = is_array($returned) ? $returned['page'] : 0; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index e9ca2d9..3df8905 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -122,7 +122,7 @@ function testCommentEditPreviewSave() { $this->drupalPost('comment/' . $comment->id . '/edit', $displayed, t('Save')); // Check that the saved comment is still correct. - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertEqual($comment_loaded->subject, $edit['subject'], 'Subject loaded.'); $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.'); $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php index 28e199e..e50c9e2 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php @@ -32,7 +32,7 @@ function testCommentRss() { // Hide comments from RSS feed and check presence. $this->node->comment = COMMENT_NODE_HIDDEN; - node_save($this->node); + $this->node->save(); $this->drupalGet('rss.xml'); $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php index 7f4edd5..09f108f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php @@ -41,7 +41,7 @@ function testCommentThreading() { $subject_text = $this->randomName(); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.'); $this->assertEqual($comment_loaded->thread, '01/'); @@ -49,14 +49,14 @@ function testCommentThreading() { $this->drupalLogin($this->web_user); $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.'); $this->assertEqual($reply_loaded->thread, '01.00/'); // Reply to comment #2 creating comment #3. $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.'); $this->assertEqual($reply_loaded->thread, '01.00.00/'); @@ -64,7 +64,7 @@ function testCommentThreading() { $this->drupalLogin($this->web_user); $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.'); $this->assertEqual($reply_loaded->thread, '01.01/'); @@ -73,7 +73,7 @@ function testCommentThreading() { $subject_text = $this->randomName(); $comment_text = $this->randomName(); $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); - $comment_loaded = comment_load($comment->id); + $comment_loaded = entity_load('comment', $comment->id); $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.'); $this->assertEqual($comment_loaded->thread, '02/'); @@ -81,14 +81,14 @@ function testCommentThreading() { $this->drupalLogin($this->web_user); $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.'); $this->assertEqual($reply_loaded->thread, '02.00/'); // Reply to comment #6 creating comment #7. $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $reply->id); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.'); $this->assertEqual($reply_loaded->thread, '02.00.00/'); @@ -96,7 +96,7 @@ function testCommentThreading() { $this->drupalLogin($this->web_user); $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); - $reply_loaded = comment_load($reply->id); + $reply_loaded = entity_load('comment', $reply->id); $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.'); $this->assertEqual($reply_loaded->thread, '02.01/'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 34674e8..4e6efa9 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -41,7 +41,7 @@ function testCommentTokenReplacement() { // Post a reply to the comment. $this->drupalGet('comment/reply/' . $node->nid . '/' . $parent_comment->id); $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName()); - $comment = comment_load($child_comment->id); + $comment = entity_load('comment', $child_comment->id); $comment->homepage = 'http://example.org/'; // Add HTML to ensure that sanitation of some fields tested directly. @@ -93,7 +93,7 @@ function testCommentTokenReplacement() { } // Load node so comment_count gets computed. - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); // Generate comment tokens for the node (it has 2 comments, both new). $tests = array(); diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index b05f4d9..8a00f7f 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -347,7 +347,7 @@ function hook_field_prepare_view($entity_type, $entities, $field, $instances, $l // use the default image. foreach ($entities as $id => $entity) { if (empty($items[$id]) && $field['settings']['default_image']) { - if ($file = file_load($field['settings']['default_image'])) { + if ($file = entity_load('file', $field['settings']['default_image'])) { $items[$id][0] = (array) $file + array( 'is_default' => TRUE, 'alt' => '', @@ -963,7 +963,7 @@ function hook_field_formatter_prepare_view($entity_type, $entities, $field, $ins } 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. diff --git a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index 5215be6..8211670 100644 --- a/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -87,7 +87,7 @@ function testOptionsAllowedValuesInteger() { $this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. - node_delete($node->nid); + entity_delete('node', $node->nid); $string = "0|Zero"; $array = array('0' => 'Zero'); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); @@ -137,7 +137,7 @@ function testOptionsAllowedValuesFloat() { $this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. - node_delete($node->nid); + entity_delete('node', $node->nid); $string = "0|Zero"; $array = array('0' => 'Zero'); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); @@ -192,7 +192,7 @@ function testOptionsAllowedValuesText() { $this->assertAllowedValuesInput("Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. - node_delete($node->nid); + entity_delete('node', $node->nid); $string = "Zero"; $array = array('Zero' => 'Zero'); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index 17d4bd7..fd1f1d9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -37,7 +37,7 @@ function setUp() { 'machine_name' => 'tags', 'langcode' => LANGUAGE_NOT_SPECIFIED, )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); $field = array( 'field_name' => 'field_' . $vocabulary->machine_name, @@ -109,7 +109,7 @@ function createField() { // Assert the field appears in the "re-use existing field" section for // different entity types; e.g. if a field was added in a node entity, it // should also appear in the 'taxonomy term' entity. - $vocabulary = taxonomy_vocabulary_load(1); + $vocabulary = entity_load('taxonomy_vocabulary', 1); $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/fields'); $this->assertTrue($this->xpath('//select[@name="fields[_add_existing_field][field_name]"]//option[@value="' . $this->field_name . '"]'), 'Existing field was found in account settings.'); } diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php index c0b0d52..c6d2635 100644 --- a/core/modules/file/file.api.php +++ b/core/modules/file/file.api.php @@ -9,14 +9,14 @@ /** * Load additional information into file entities. * - * file_load_multiple() calls this hook to allow modules to load - * additional information into each file. + * entity_load_multiple() calls this hook to allow modules to load additional + * information into each file. * * @param $files * An array of file entities, indexed by fid. * - * @see file_load_multiple() - * @see file_load() + * @see entity_load_multiple() + * @see entity_load() */ function hook_file_load($files) { // Add the upload specific data into the file entity. diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index cbc2246..8b24025 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -198,7 +198,7 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l // Ensure consecutive deltas. $items[$id] = array_values($items[$id]); } - $files = file_load_multiple($fids); + $files = entity_load_multiple('file', $fids); foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { @@ -219,7 +219,7 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l function file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { // Add a new usage of each uploaded file. foreach ($items as $item) { - file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id()); + file_usage_add(entity_load('file', $item['fid']), 'file', $entity_type, $entity->id()); } } @@ -233,7 +233,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode, // deletion of previous file usages are necessary. if (!empty($entity->revision)) { foreach ($items as $item) { - file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id()); + file_usage_add(entity_load('file', $item['fid']), 'file', $entity_type, $entity->id()); } return; } @@ -252,7 +252,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode, $original_fids[] = $original_item['fid']; if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) { // Decrement the file usage count by 1. - file_usage_delete(file_load($original_item['fid']), 'file', $entity_type, $entity->id()); + file_usage_delete(entity_load('file', $original_item['fid']), 'file', $entity_type, $entity->id()); } } } @@ -260,7 +260,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode, // Add new usage entries for newly added files. foreach ($items as $item) { if (!in_array($item['fid'], $original_fids)) { - file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id()); + file_usage_add(entity_load('file', $item['fid']), 'file', $entity_type, $entity->id()); } } } @@ -271,7 +271,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode, function file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { // Delete all file usages within this entity. foreach ($items as $delta => $item) { - file_usage_delete(file_load($item['fid']), 'file', $entity_type, $entity->id(), 0); + file_usage_delete(entity_load('file', $item['fid']), 'file', $entity_type, $entity->id(), 0); } } @@ -281,7 +281,7 @@ function file_field_delete($entity_type, $entity, $field, $instance, $langcode, function file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) { foreach ($items as $delta => $item) { // Decrement the file usage count by 1. - file_usage_delete(file_load($item['fid']), 'file', $entity_type, $entity->id()); + file_usage_delete(entity_load('file', $item['fid']), 'file', $entity_type, $entity->id()); } } diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 0f6cb64..908c44f 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -104,23 +104,6 @@ function file_entity_info() { ), ); } -/** - * Loads file entities from the database. - * - * @param array $fids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * - * @return array - * An array of file entities, indexed by fid. - * - * @see hook_file_load() - * @see file_load() - * @see entity_load() - * @see Drupal\Core\Entity\EntityFieldQuery - */ -function file_load_multiple(array $fids = NULL) { - return entity_load_multiple('file', $fids); -} /** * Loads a single file entity from the database. @@ -133,6 +116,10 @@ function file_load_multiple(array $fids = NULL) { * * @see hook_file_load() * @see file_load_multiple() + * + * @deprecated + * Wrappers for entity_load() will be removed once they are no longer required + * as load callbacks in the menu system. */ function file_load($fid) { $files = file_load_multiple(array($fid)); @@ -875,7 +862,7 @@ function file_cron() { ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE )); foreach ($result as $row) { - if ($file = file_load($row->fid)) { + if ($file = entity_load('file', $row->fid)) { $references = file_usage_list($file); if (empty($references)) { if (file_exists($file->uri)) { @@ -1035,7 +1022,7 @@ function file_managed_file_process($element, &$form_state, $form) { // Set some default element properties. $element['#progress_indicator'] = empty($element['#progress_indicator']) ? 'none' : $element['#progress_indicator']; - $element['#file'] = $fid ? file_load($fid) : FALSE; + $element['#file'] = $fid ? entity_load('file', $fid) : FALSE; $element['#tree'] = TRUE; $ajax_settings = array( @@ -1187,7 +1174,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) } } // Load file if the FID has changed to confirm it exists. - if (isset($input['fid']) && $file = file_load($input['fid'])) { + if (isset($input['fid']) && $file = entity_load('file', $input['fid'])) { $fid = $file->fid; } } @@ -1205,7 +1192,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) } // Confirm that the file exists when used as a default value. - if ($default_fid && $file = file_load($default_fid)) { + if ($default_fid && $file = entity_load('file', $default_fid)) { $fid = $file->fid; } } @@ -1227,7 +1214,7 @@ function file_managed_file_validate(&$element, &$form_state) { // item were to be deleted. $clicked_button = end($form_state['triggering_element']['#parents']); if ($clicked_button != 'remove_button' && !empty($element['fid']['#value'])) { - if ($file = file_load($element['fid']['#value'])) { + if ($file = entity_load('file', $element['fid']['#value'])) { if ($file->status == FILE_STATUS_PERMANENT) { $references = file_usage_list($file); if (empty($references)) { @@ -1272,7 +1259,7 @@ function file_managed_file_submit($form, &$form_state) { // it's up to the implementing module to remove usages of files to have them // removed. if ($element['#file'] && $element['#file']->status == 0) { - file_delete($element['#file']->fid); + entity_delete('file', $element['#file']->fid); } // Update both $form_state['values'] and $form_state['input'] to reflect // that the file has been removed, so that the form is rebuilt correctly. @@ -1407,7 +1394,7 @@ function theme_file_link($variables) { $url = file_create_url($file->uri); // theme_file_icon() requires a file entity, make sure it gets one. - $icon = theme('file_icon', array('file' => ($file instanceof File) ? $file : file_load($file->fid), 'icon_directory' => $icon_directory)); + $icon = theme('file_icon', array('file' => ($file instanceof File) ? $file : entity_load('file', $file->fid), 'icon_directory' => $icon_directory)); // Set options as per anchor format described at // http://microformats.org/wiki/file-format-examples diff --git a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php index 7f20c9f..9e32c66 100644 --- a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php @@ -45,7 +45,7 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); } /** @@ -72,9 +72,9 @@ function testExistingRename() { // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->fid, TRUE); - $loaded_target = file_load($target->fid, TRUE); - $loaded_result = file_load($result->fid, TRUE); + $loaded_source = entity_load('file', $source->fid, TRUE); + $loaded_target = entity_load('file', $target->fid, TRUE); + $loaded_result = entity_load('file', $result->fid, TRUE); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -112,9 +112,9 @@ function testExistingReplace() { // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->fid, TRUE); - $loaded_target = file_load($target->fid, TRUE); - $loaded_result = file_load($result->fid, TRUE); + $loaded_source = entity_load('file', $source->fid, TRUE); + $loaded_target = entity_load('file', $target->fid, TRUE); + $loaded_result = entity_load('file', $result->fid, TRUE); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -147,7 +147,7 @@ function testExistingError() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); - $this->assertFileUnchanged($source, file_load($source->fid, TRUE)); - $this->assertFileUnchanged($target, file_load($target->fid, TRUE)); + $this->assertFileUnchanged($source, entity_load('file', $source->fid, TRUE)); + $this->assertFileUnchanged($target, entity_load('file', $target->fid, TRUE)); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php index be2f8a4..d85e8b1 100644 --- a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php @@ -30,7 +30,7 @@ function testUnused() { $file->delete(); $this->assertFileHooksCalled(array('delete', 'load')); $this->assertFalse(file_exists($file->uri), t('Test file has actually been deleted.')); - $this->assertFalse(file_load($file->fid), t('File was removed from the database.')); + $this->assertFalse(entity_load('file', $file->fid), t('File was removed from the database.')); } /** @@ -45,7 +45,7 @@ function testInUse() { $usage = file_usage_list($file); $this->assertEqual($usage['testing']['test'], array(1 => 1), t('Test file is still in use.')); $this->assertTrue(file_exists($file->uri), t('File still exists on the disk.')); - $this->assertTrue(file_load($file->fid), t('File still exists in the database.')); + $this->assertTrue(entity_load('file', $file->fid), t('File still exists in the database.')); // Clear out the call to hook_file_load(). file_test_reset(); @@ -55,7 +55,7 @@ function testInUse() { $this->assertFileHooksCalled(array('load', 'update')); $this->assertTrue(empty($usage), t('File usage data was removed.')); $this->assertTrue(file_exists($file->uri), 'File still exists on the disk.'); - $file = file_load($file->fid); + $file = entity_load('file', $file->fid); $this->assertTrue($file, 'File still exists in the database.'); $this->assertEqual($file->status, 0, 'File is temporary.'); file_test_reset(); @@ -73,6 +73,6 @@ function testInUse() { // system_cron() loads $this->assertFileHooksCalled(array('load', 'delete')); $this->assertFalse(file_exists($file->uri), t('File has been deleted after its last usage was removed.')); - $this->assertFalse(file_load($file->fid), t('File was removed from the database.')); + $this->assertFalse(entity_load('file', $file->fid), t('File was removed from the database.')); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 9d7dd30..8787a4b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -57,8 +57,8 @@ function testNodeDisplay() { $this->drupalGet('node/' . $nid . '/edit'); // Check that the default formatter is displaying with the file name. - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $default_output = theme('file_link', array('file' => $node_file)); $this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index d963b89..02e55c0 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -32,8 +32,8 @@ function testUploadPath() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded to the file root. - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri))); // Change the path to contain multiple subdirectories. @@ -43,8 +43,8 @@ function testUploadPath() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded into the subdirectory. - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri))); // Check the path when used with tokens. @@ -55,8 +55,8 @@ function testUploadPath() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded into the subdirectory. - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index 480f411..f35e2cc 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -46,8 +46,8 @@ function testRevisions() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file exists on disk and in the database. - $node = node_load($nid, TRUE); - $node_file_r1 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file_r1 = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $node_vid_r1 = $node->vid; $this->assertFileExists($node_file_r1, t('New file saved to disk on node creation.')); $this->assertFileEntryExists($node_file_r1, t('File entry exists in database on node creation.')); @@ -55,8 +55,8 @@ function testRevisions() { // Upload another file to the same node in a new revision. $this->replaceNodeFile($test_file, $field_name, $nid); - $node = node_load($nid, TRUE); - $node_file_r2 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file_r2 = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $node_vid_r2 = $node->vid; $this->assertFileExists($node_file_r2, t('Replacement file exists on disk after creating new revision.')); $this->assertFileEntryExists($node_file_r2, t('Replacement file entry exists in database after creating new revision.')); @@ -64,7 +64,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $this->assertEqual($node_file_r1, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.')); + $this->assertEqual($node_file_r1, entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.')); $this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.')); $this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision')); $this->assertFileIsPermanent($node_file_r1, t('Original file is still permanent.')); @@ -72,16 +72,16 @@ function testRevisions() { // Save a new version of the node without any changes. // Check that the file is still the same as the previous revision. $this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save')); - $node = node_load($nid, TRUE); - $node_file_r3 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file_r3 = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $node_vid_r3 = $node->vid; $this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.')); $this->assertFileIsPermanent($node_file_r3, t('New revision file is permanent.')); // Revert to the first revision and check that the original file is active. $this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); - $node = node_load($nid, TRUE); - $node_file_r4 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file_r4 = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $node_vid_r4 = $node->vid; $this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.')); $this->assertFileIsPermanent($node_file_r4, t('Original revision file still permanent after reverting to the original revision.')); @@ -107,7 +107,7 @@ function testRevisions() { $this->assertFileIsPermanent($node_file_r3, t('Second file entry is still permanent after deleting third revision, since it is being used by the user.')); // Delete the user and check that the file is also deleted. - user_delete($user->uid); + entity_delete('user', $user->uid); // TODO: This seems like a bug in File API. Clearing the stat cache should // not be necessary here. The file really is deleted, but stream wrappers // doesn't seem to think so unless we clear the PHP file stat() cache. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index e291bec..4453910 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -38,7 +38,7 @@ function getTestFile($type_name, $size = NULL) { // Get a file to upload. $file = current($this->drupalGetTestFiles($type_name, $size)); - // Add a filesize property to files as would be read by file_load(). + // Add a filesize property to files as would be read by entity_load(). $file->filesize = filesize($file->uri); return entity_create('file', (array) $file); @@ -143,7 +143,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $nid = $node->nid; // Save at least one revision to better simulate a real site. $this->drupalCreateNode(get_object_vars($node)); - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); $this->assertNotEqual($nid, $node->vid, t('Node revision exists.')); } @@ -194,7 +194,7 @@ function assertFileExists($file, $message = NULL) { */ function assertFileEntryExists($file, $message = NULL) { entity_get_controller('file')->resetCache(); - $db_file = file_load($file->fid); + $db_file = entity_load('file', $file->fid); $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->uri)); $this->assertEqual($db_file->uri, $file->uri, $message); } @@ -213,7 +213,7 @@ function assertFileNotExists($file, $message = NULL) { function assertFileEntryNotExists($file, $message) { entity_get_controller('file')->resetCache(); $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->uri)); - $this->assertFalse(file_load($file->fid), $message); + $this->assertFalse(entity_load('file', $file->fid), $message); } /** diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 050931b..2e0df69 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -44,9 +44,9 @@ function testRequired() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $this->assertTrue($nid !== FALSE, t('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->uri, '@field_name' => $field_name, '@type_name' => $type_name))); - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading to the required field.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required field.')); @@ -61,8 +61,8 @@ function testRequired() { // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading to the required multiple value field.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required multipel value field.')); @@ -97,8 +97,8 @@ function testFileMaxSize() { // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize))); @@ -113,8 +113,8 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); @@ -140,8 +140,8 @@ function testFileExtension() { // Check that the file can be uploaded with no extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file with no extension checking.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with no extension checking.')); @@ -158,8 +158,8 @@ function testFileExtension() { // Check that the file can be uploaded with extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 0bb8866..42abfc7 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -41,8 +41,8 @@ function testSingleValuedWidget() { // @todo This only tests a 'nojs' submission, because drupalPostAJAX() // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('New file saved to disk on node creation.')); // Ensure the file can be downloaded. @@ -74,7 +74,7 @@ function testSingleValuedWidget() { // Save the node and ensure it does not have the file. $this->drupalPost(NULL, array(), t('Save')); - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); $this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('File was successfully removed from the node.')); } } @@ -195,7 +195,7 @@ function testMultiValuedWidget() { $matches = array(); preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); $this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Node was successfully saved without any files.')); } } @@ -220,8 +220,8 @@ function testPrivateFileSetting() { $edit = array('field[settings][uri_scheme]' => 'private'); $this->drupalPost("admin/structure/types/manage/$type_name/fields/$field_name", $edit, t('Save settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('New file saved to disk on node creation.')); // Ensure the private file is available to the user who uploaded it. @@ -234,7 +234,7 @@ function testPrivateFileSetting() { $this->assertFieldByXpath('//input[@id="edit-field-settings-uri-scheme-public" and @disabled="disabled"]', 'public', t('Upload destination setting disabled.')); // Delete node and confirm that setting could be changed. - node_delete($nid); + entity_delete('node', $nid); $this->drupalGet("admin/structure/types/manage/$type_name/fields/$field_name"); $this->assertFieldByXpath('//input[@id="edit-field-settings-uri-scheme-public" and not(@disabled)]', 'public', t('Upload destination setting enabled.')); } @@ -286,8 +286,8 @@ function testPrivateFileComment() { // Log in as normal user. $this->drupalLogin($user); - $comment = comment_load($cid); - $comment_file = file_load($comment->{'field_' . $name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $comment = entity_load('comment', $cid); + $comment_file = entity_load('file', $comment->{'field_' . $name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($comment_file, t('New file saved to disk on node creation.')); // Test authenticated file download. $url = file_create_url($comment_file->uri); diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php index 2febd5f..3274ac6 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php @@ -51,8 +51,8 @@ function testPrivateFile() { $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->uri)); $this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.')); @@ -63,8 +63,8 @@ function testPrivateFile() { // Test with the field that should deny access through field access. $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); - $node = node_load($nid, TRUE); - $node_file = file_load($node->{$no_access_field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $node_file = entity_load('file', $node->{$no_access_field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->uri)); $this->assertResponse(403, t('Confirmed that access is denied for the file without view field access permission.')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 4d56b7b..ccc1366 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -45,8 +45,8 @@ function testFileTokenReplacement() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Load the node and the file. - $node = node_load($nid, TRUE); - $file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node = entity_load('node', $nid, TRUE); + $file = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php index 833c260..efd690e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php @@ -8,13 +8,13 @@ namespace Drupal\file\Tests; /** - * Tests the file_load() function. + * Tests the entity_load() function. */ class LoadTest extends FileManagedTestBase { public static function getInfo() { return array( 'name' => 'File loading', - 'description' => 'Tests the file_load() function.', + 'description' => 'Tests the entity_load() function.', 'group' => 'File API', ); } @@ -23,7 +23,7 @@ public static function getInfo() { * Try to load a non-existent file by fid. */ function testLoadMissingFid() { - $this->assertFalse(file_load(-1), t("Try to load an invalid fid fails.")); + $this->assertFalse(entity_load('file', -1), t("Try to load an invalid fid fails.")); $this->assertFileHooksCalled(array()); } @@ -52,9 +52,9 @@ function testSingleValues() { // Create a new file entity from scratch so we know the values. $file = $this->createFile('druplicon.txt', NULL, 'public'); - $by_fid_file = file_load($file->fid); + $by_fid_file = entity_load('file', $file->fid); $this->assertFileHookCalled('load'); - $this->assertTrue(is_object($by_fid_file), t('file_load() returned an object.')); + $this->assertTrue(is_object($by_fid_file), t('entity_load() returned an object.')); $this->assertEqual($by_fid_file->fid, $file->fid, t("Loading by fid got the same fid."), 'File'); $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File'); $this->assertEqual($by_fid_file->filename, $file->filename, t("Loading by fid got the correct filename."), 'File'); @@ -74,16 +74,16 @@ function testMultiple() { file_test_reset(); $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri)); $this->assertFileHookCalled('load'); - $this->assertEqual(1, count($by_path_files), t('file_load_multiple() returned an array of the correct size.')); + $this->assertEqual(1, count($by_path_files), t('entity_load_multiple() returned an array of the correct size.')); $by_path_file = reset($by_path_files); $this->assertTrue($by_path_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.')); $this->assertEqual($by_path_file->fid, $file->fid, t("Loading by filepath got the correct fid."), 'File'); // Load by fid. file_test_reset(); - $by_fid_files = file_load_multiple(array($file->fid)); + $by_fid_files = entity_load_multiple('file', array($file->fid)); $this->assertFileHookCalled('load'); - $this->assertEqual(1, count($by_fid_files), t('file_load_multiple() returned an array of the correct size.')); + $this->assertEqual(1, count($by_fid_files), t('entity_load_multiple() returned an array of the correct size.')); $by_fid_file = reset($by_fid_files); $this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.')); $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File'); diff --git a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php index 15868b1..afc5a6b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php @@ -44,7 +44,7 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_file = file_load($result->fid, TRUE); + $loaded_file = entity_load('file', $result->fid, TRUE); $this->assertTrue($loaded_file, t('File can be loaded from the database.')); $this->assertFileUnchanged($result, $loaded_file); } @@ -72,14 +72,14 @@ function testExistingRename() { $this->assertFileHooksCalled(array('move', 'load', 'update')); // Compare the returned value to what made it into the database. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); // The target file should not have been altered. - $this->assertFileUnchanged($target, file_load($target->fid, TRUE)); + $this->assertFileUnchanged($target, entity_load('file', $target->fid, TRUE)); // Make sure we end up with two distinct files afterwards. $this->assertDifferentFile($target, $result); // Compare the source and results. - $loaded_source = file_load($source->fid, TRUE); + $loaded_source = entity_load('file', $source->fid, TRUE); $this->assertEqual($loaded_source->fid, $result->fid, t("Returned file's id matches the source.")); $this->assertNotEqual($loaded_source->uri, $source->uri, t("Returned file path has changed from the original.")); } @@ -108,7 +108,7 @@ function testExistingReplace() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_result = file_load($result->fid, TRUE); + $loaded_result = entity_load('file', $result->fid, TRUE); $this->assertFileUnchanged($result, $loaded_result); // Check that target was re-used. $this->assertSameFile($target, $loaded_result); @@ -135,7 +135,7 @@ function testExistingReplaceSelf() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->fid, TRUE)); + $this->assertFileUnchanged($source, entity_load('file', $source->fid, TRUE)); } /** @@ -162,7 +162,7 @@ function testExistingError() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->fid, TRUE)); - $this->assertFileUnchanged($target, file_load($target->fid, TRUE)); + $this->assertFileUnchanged($source, entity_load('file', $source->fid, TRUE)); + $this->assertFileUnchanged($target, entity_load('file', $target->fid, TRUE)); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php index ecdb201..7613454 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php @@ -38,7 +38,7 @@ function testWithoutFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); } /** @@ -63,7 +63,7 @@ function testWithFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); } /** @@ -88,10 +88,10 @@ function testExistingRename() { // Ensure that the existing file wasn't overwritten. $this->assertDifferentFile($existing, $result); - $this->assertFileUnchanged($existing, file_load($existing->fid, TRUE)); + $this->assertFileUnchanged($existing, entity_load('file', $existing->fid, TRUE)); // Verify that was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); } /** @@ -118,7 +118,7 @@ function testExistingReplace() { $this->assertSameFile($existing, $result); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->fid, TRUE)); + $this->assertFileUnchanged($result, entity_load('file', $result->fid, TRUE)); } /** @@ -137,6 +137,6 @@ function testExistingError() { $this->assertFileHooksCalled(array()); // Ensure that the existing file wasn't overwritten. - $this->assertFileUnchanged($existing, file_load($existing->fid, TRUE)); + $this->assertFileUnchanged($existing, entity_load('file', $existing->fid, TRUE)); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php index c2adbd6..e3d2f95 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php @@ -71,7 +71,7 @@ function setUp() { function testNormal() { $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.')); - $file1 = file_load($max_fid_after); + $file1 = entity_load('file', $max_fid_after); $this->assertTrue($file1, t('Loaded the file.')); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file1->filemime, 0, 5), 'image', 'A MIME type was set.'); @@ -91,13 +91,13 @@ function testNormal() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); - $file2 = file_load($max_fid_after); + $file2 = entity_load('file', $max_fid_after); $this->assertTrue($file2); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file2->filemime, 0, 5), 'image', 'A MIME type was set.'); - // Load both files using file_load_multiple(). - $files = file_load_multiple(array($file1->fid, $file2->fid)); + // Load both files using entity_load_multiple(). + $files = entity_load_multiple('file', array($file1->fid, $file2->fid)); $this->assertTrue(isset($files[$file1->fid]), t('File was loaded successfully')); $this->assertTrue(isset($files[$file2->fid]), t('File was loaded successfully')); diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index e3c564a..3fabf1c 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -101,7 +101,7 @@ function forum_form_submit($form, &$form_state) { // @todo Set explicit entity properties instead of arbitrary form values. form_state_values_clean($form_state); $term = entity_create('taxonomy_term', $form_state['values']); - $status = taxonomy_term_save($term); + $status = $term->save(); switch ($status) { case SAVED_NEW: if ($container) { @@ -209,7 +209,7 @@ function forum_form_container($form, &$form_state, $edit = array()) { * @ingroup forms */ function forum_confirm_delete($form, &$form_state, $tid) { - $term = taxonomy_term_load($tid); + $term = entity_load('taxonomy_term', $tid); $form['tid'] = array('#type' => 'value', '#value' => $tid); $form['name'] = array('#type' => 'value', '#value' => $term->label()); @@ -221,7 +221,7 @@ function forum_confirm_delete($form, &$form_state, $tid) { * Form submission handler for forum_confirm_delete(). */ function forum_confirm_delete_submit($form, &$form_state) { - taxonomy_term_delete($form_state['values']['tid']); + entity_delete('taxonomy_term', $form_state['values']['tid']); drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name']))); watchdog('content', 'forum: deleted %term and all its sub-forums.', array('%term' => $form_state['values']['name'])); @@ -288,7 +288,7 @@ function forum_overview($form, &$form_state) { $config = config('forum.settings'); $vid = $config->get('vocabulary'); - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); $form = taxonomy_overview_terms($form, $form_state, $vocabulary); foreach (element_children($form) as $key) { diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 56f8402..39da35d 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -33,7 +33,7 @@ function forum_enable() { $config = config('forum.settings'); // If the module was disabled only, the current config may contain a valid // vocabulary ID already. - $vocabulary = taxonomy_vocabulary_load($config->get('vocabulary')); + $vocabulary = entity_load('taxonomy_vocabulary', $config->get('vocabulary')); if (!$vocabulary) { // If the module was installed and uninstalled previously, the vocabulary // with machine name 'forums' might still exist. @@ -49,7 +49,7 @@ function forum_enable() { 'module' => 'forum', 'weight' => -10, )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); } $config->set('vocabulary', $vocabulary->vid)->save(); } @@ -78,7 +78,7 @@ function forum_enable() { 'parent' => array(0), 'vid' => $vocabulary->vid, )); - taxonomy_term_save($term); + $term->save(); // Create the instance on the bundle. $instance = array( diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index f365491..91ac781 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -222,8 +222,8 @@ function forum_entity_info_alter(&$info) { if ($vid = config('forum.settings')->get('vocabulary')) { // Within hook_entity_info(), we can't invoke entity_load() as that would // cause infinite recursion, so we call taxonomy_vocabulary_get_names() - // instead of taxonomy_vocabulary_load(). All we need is the machine name - // of $vid, so retrieving and iterating all the vocabulary names is somewhat + // instead of entity_load(). All we need is the machine name of $vid, so + // retrieving and iterating all the vocabulary names is somewhat // inefficient, but entity info is cached across page requests, and an // iteration of all vocabularies once per cache clearing isn't a big deal, // and is done as part of taxonomy_entity_info() anyway. @@ -264,7 +264,7 @@ function _forum_node_check_node_type(Node $node) { */ function forum_node_view(Node $node, $view_mode) { $vid = config('forum.settings')->get('vocabulary'); - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); if (_forum_node_check_node_type($node)) { if ($view_mode == 'full' && node_is_page($node)) { // Breadcrumb navigation @@ -302,7 +302,7 @@ function forum_node_validate(Node $node, $form) { unset($node->taxonomy_forums[$langcode][$delta]); continue; } - $term = taxonomy_term_load($item['tid']); + $term = entity_load('taxonomy_term', $item['tid']); if (!$term) { form_set_error('taxonomy_forums', t('Select a forum.')); continue; @@ -779,7 +779,7 @@ function forum_forum_load($tid = NULL) { // Load and validate the parent term. if ($tid) { - $forum_term = taxonomy_term_load($tid); + $forum_term = entity_load('taxonomy_term', $tid); if (!$forum_term || ($forum_term->vid != $vid)) { return $cache[$tid] = FALSE; } @@ -954,7 +954,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { $nids[] = $record->nid; } if ($nids) { - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); $query = db_select('node', 'n') ->extend('Drupal\Core\Database\Query\TableSortExtender'); @@ -1068,7 +1068,7 @@ function template_preprocess_forums(&$variables) { $config = config('forum.settings'); $vid = $config->get('vocabulary'); - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = entity_load('taxonomy_vocabulary', $vid); $title = !empty($vocabulary->name) ? $vocabulary->name : ''; // Breadcrumb navigation: diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index a253e2b..29afb77 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -226,7 +226,7 @@ function testAddOrphanTopic() { $vid = config('forum.settings')->get('vocabulary'); $tree = taxonomy_get_tree($vid); foreach ($tree as $term) { - taxonomy_term_delete($term->tid); + entity_delete('taxonomy_term', $term->tid); } // Create an orphan forum item. @@ -319,7 +319,7 @@ private function doAdminTests($user) { 'langcode' => language_default()->langcode, 'help' => $help, )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); // Test tags vocabulary form is not affected. $this->drupalGet('admin/structure/taxonomy/tags/edit'); $this->assertFieldByName('op', t('Save'), 'Save button found.'); @@ -338,7 +338,7 @@ private function doAdminTests($user) { function editForumTaxonomy() { // Backup forum taxonomy. $vid = config('forum.settings')->get('vocabulary'); - $original_settings = taxonomy_vocabulary_load($vid); + $original_settings = entity_load('taxonomy_vocabulary', $vid); // Generate a random name/description. $title = $this->randomName(10); @@ -357,16 +357,16 @@ function editForumTaxonomy() { // Grab the newly edited vocabulary. entity_get_controller('taxonomy_vocabulary')->resetCache(); - $current_settings = taxonomy_vocabulary_load($vid); + $current_settings = entity_load('taxonomy_vocabulary', $vid); // Make sure we actually edited the vocabulary properly. $this->assertEqual($current_settings->name, $title, 'The name was updated'); $this->assertEqual($current_settings->description, $description, 'The description was updated'); // Restore the original vocabulary. - taxonomy_vocabulary_save($original_settings); + $original_settings->save(); drupal_static_reset('taxonomy_vocabulary_load'); - $current_settings = taxonomy_vocabulary_load($vid); + $current_settings = entity_load('taxonomy_vocabulary', $vid); $this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored'); } diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index 09b07eb..09f7e65 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -199,7 +199,7 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $ } // Add the default image if one is found. - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = entity_load('file', $fid))) { $items[$id][0] = (array) $file + array( 'is_default' => TRUE, 'alt' => '', @@ -218,7 +218,7 @@ function image_field_presave($entity_type, $entity, $field, $instance, $langcode // Determine the dimensions if necessary. foreach ($items as &$item) { if (!isset($item['width']) || !isset($item['height'])) { - $info = image_get_info(file_load($item['fid'])->uri); + $info = image_get_info(entity_load('file', $item['fid'])->uri); if (is_array($info)) { $item['width'] = $info['width']; diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 01d2b3b..ea826aa 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -372,7 +372,7 @@ function image_field_delete_field($field) { // The value of a managed_file element can be an array if #extended == TRUE. $fid = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = entity_load('file', $fid))) { file_usage_delete($file, 'image', 'default_image', $field['id']); } } @@ -389,7 +389,7 @@ function image_field_update_field($field, $prior_field, $has_data) { $fid_new = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); $fid_old = (is_array($prior_field['settings']['default_image']) ? $prior_field['settings']['default_image']['fid'] : $prior_field['settings']['default_image']); - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? entity_load('file', $fid_new) : FALSE; if ($fid_new != $fid_old) { @@ -401,7 +401,7 @@ function image_field_update_field($field, $prior_field, $has_data) { } // Is there an old file? - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = entity_load('file', $fid_old))) { file_usage_delete($file_old, 'image', 'default_image', $field['id']); } } @@ -432,7 +432,7 @@ function image_field_delete_instance($instance) { } // Remove the default image when the instance is deleted. - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = entity_load('file', $fid))) { file_usage_delete($file, 'image', 'default_image', $instance['id']); } } @@ -459,7 +459,7 @@ function image_field_update_instance($instance, $prior_instance) { } // If the old and new files do not match, update the default accordingly. - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? entity_load('file', $fid_new) : FALSE; if ($fid_new != $fid_old) { // Save the new file, if present. if ($file_new) { @@ -468,7 +468,7 @@ function image_field_update_instance($instance, $prior_instance) { file_usage_add($file_new, 'image', 'default_image', $instance['id']); } // Delete the old file, if present. - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = entity_load('file', $fid_old))) { file_usage_delete($file_old, 'image', 'default_image', $instance['id']); } } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 7437b10..33e44f1 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -238,11 +238,11 @@ function testStyleReplacement() { // Create a new node with an image attached. $test_image = current($this->drupalGetTestFiles('image')); $nid = $this->uploadNodeImage($test_image, $field_name, 'article'); - $node = node_load($nid); + $node = entity_load('node', $nid); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), format_string('Image displayed using style @style.', array('@style' => $style_name))); + $this->assertRaw(image_style_url($style_name, entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), format_string('Image displayed using style @style.', array('@style' => $style_name))); // Rename the style and make sure the image field is updated. $new_style_name = strtolower($this->randomName(10)); @@ -254,7 +254,7 @@ function testStyleReplacement() { $this->drupalPost('admin/config/media/image-styles/edit/' . $style_name, $edit, t('Update style')); $this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name))); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url($new_style_name, entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); // Delete the style and choose a replacement style. $edit = array( @@ -265,7 +265,7 @@ function testStyleReplacement() { $this->assertRaw($message); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url('thumbnail', entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); } /** diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index f7670fe..b1fc5ec 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -149,8 +149,8 @@ function testDefaultImages() { ); // Reload the nodes and confirm the field instance defaults are used. - $article_built = node_view($article = node_load($article->nid, TRUE)); - $page_built = node_view($page = node_load($page->nid, TRUE)); + $article_built = node_view($article = entity_load('node', $article->nid, TRUE)); + $page_built = node_view($page = entity_load('node', $page->nid, TRUE)); $this->assertEqual( $article_built[$field_name]['#items'][0]['fid'], $default_images['instance']->fid, @@ -185,8 +185,8 @@ function testDefaultImages() { ); // Reload the nodes. - $article_built = node_view($article = node_load($article->nid, TRUE)); - $page_built = node_view($page = node_load($page->nid, TRUE)); + $article_built = node_view($article = entity_load('node', $article->nid, TRUE)); + $page_built = node_view($page = entity_load('node', $page->nid, TRUE)); // Confirm the article uses the new default. $this->assertEqual( @@ -220,8 +220,8 @@ function testDefaultImages() { ); // Reload the nodes. - $article_built = node_view($article = node_load($article->nid, TRUE)); - $page_built = node_view($page = node_load($page->nid, TRUE)); + $article_built = node_view($article = entity_load('node', $article->nid, TRUE)); + $page_built = node_view($page = entity_load('node', $page->nid, TRUE)); // Confirm the article uses the new field (not instance) default. $this->assertEqual( $article_built[$field_name]['#items'][0]['fid'], diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index c6ac2d8..35370bf 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -52,10 +52,10 @@ function _testImageFieldFormatters($scheme) { // Create a new node with an image attached. $test_image = current($this->drupalGetTestFiles('image')); $nid = $this->uploadNodeImage($test_image, $field_name, 'article'); - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri; + $image_uri = entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri; $image_info = array( 'uri' => $image_uri, 'width' => 40, @@ -157,9 +157,9 @@ function testImageFieldSettings() { $this->assertFieldByName($field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]', '', 'Title field displayed on article form.'); // Verify that the attached image is being previewed using the 'medium' // style. - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, 'width' => 220, 'height' => 110, 'style_name' => 'medium', @@ -169,7 +169,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, 'alt' => $this->randomName(), 'title' => $this->randomName(), 'width' => 40, @@ -225,7 +225,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field($field_name); - $image = file_load($field['settings']['default_image']); + $image = entity_load('file', $field['settings']['default_image']); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); $default_output = theme('image', array('uri' => $image->uri)); $this->drupalGet('node/' . $node->nid); @@ -234,9 +234,9 @@ function testImageFieldDefaultImage() { // Create a node with an image attached and ensure that the default image // is not displayed. $nid = $this->uploadNodeImage($images[1], $field_name, 'article'); - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => entity_load('file', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, 'width' => 40, 'height' => 20, ); @@ -264,7 +264,7 @@ function testImageFieldDefaultImage() { ); $this->drupalPost('admin/structure/types/manage/article/fields/' . $private_field_name, $edit, t('Save settings')); $private_field = field_info_field($private_field_name); - $image = file_load($private_field['settings']['default_image']); + $image = entity_load('file', $private_field['settings']['default_image']); $this->assertEqual('private', file_uri_scheme($image->uri), 'Default image uses private:// scheme.'); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); // Create a new node with no image attached and ensure that default private diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index b4cd7e7..9b83bd6 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -60,7 +60,7 @@ function testMenu() { $this->drupalLogin($this->std_user); $this->verifyAccess(403); foreach ($this->items as $item) { - $node = node_load(substr($item['link_path'], 5)); // Paths were set as 'node/$nid'. + $node = entity_load('node', substr($item['link_path'], 5)); // Paths were set as 'node/$nid'. $this->verifyMenuLink($item, $node); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessRecordsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessRecordsTest.php index 07a00cf..8936b33 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessRecordsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessRecordsTest.php @@ -33,7 +33,7 @@ public static function getInfo() { function testNodeAccessRecords() { // Create an article node. $node1 = $this->drupalCreateNode(array('type' => 'article')); - $this->assertTrue(node_load($node1->nid), 'Article node created.'); + $this->assertTrue(entity_load('node', $node1->nid), 'Article node created.'); // Check to see if grants added by node_test_node_access_records made it in. $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll(); @@ -43,7 +43,7 @@ function testNodeAccessRecords() { // Create an unpromoted "Basic page" node. $node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0)); - $this->assertTrue(node_load($node2->nid), 'Unpromoted basic page node created.'); + $this->assertTrue(entity_load('node', $node2->nid), 'Unpromoted basic page node created.'); // Check to see if grants added by node_test_node_access_records made it in. $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll(); @@ -53,7 +53,7 @@ function testNodeAccessRecords() { // Create an unpromoted, unpublished "Basic page" node. $node3 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0, 'status' => 0)); - $this->assertTrue(node_load($node3->nid), 'Unpromoted, unpublished basic page node created.'); + $this->assertTrue(entity_load('node', $node3->nid), 'Unpromoted, unpublished basic page node created.'); // Check to see if grants added by node_test_node_access_records made it in. $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node3->nid))->fetchAll(); @@ -63,7 +63,7 @@ function testNodeAccessRecords() { // Create a promoted "Basic page" node. $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); - $this->assertTrue(node_load($node4->nid), 'Promoted basic page node created.'); + $this->assertTrue(entity_load('node', $node4->nid), 'Promoted basic page node created.'); // Check to see if grant added by node_test_node_access_records was altered // by node_test_node_access_records_alter. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeLoadHooksTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeLoadHooksTest.php index 5ca7ed6..8567726 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeLoadHooksTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeLoadHooksTest.php @@ -8,7 +8,7 @@ namespace Drupal\node\Tests; /** - * Tests for the hooks invoked during node_load(). + * Tests for the hooks invoked during entity_load(). */ class NodeLoadHooksTest extends NodeTestBase { diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeLoadMultipleTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeLoadMultipleTest.php index 815ab1b..03e71ad 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeLoadMultipleTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeLoadMultipleTest.php @@ -8,7 +8,7 @@ namespace Drupal\node\Tests; /** - * Tests the node_load_multiple() function. + * Tests the entity_load_multiple() function. */ class NodeLoadMultipleTest extends NodeTestBase { @@ -50,7 +50,7 @@ function testNodeMultipleLoad() { $this->assertTrue($count == 2, t('@count nodes loaded.', array('@count' => $count))); // Load nodes by nid. Nodes 1, 2 and 4 will be loaded. - $nodes = node_load_multiple(array(1, 2, 4)); + $nodes = entity_load_multiple('node', array(1, 2, 4)); $count = count($nodes); $this->assertTrue(count($nodes) == 3, t('@count nodes loaded', array('@count' => $count))); $this->assertTrue(isset($nodes[$node1->nid]), 'Node is correctly keyed in the array'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionPermissionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionPermissionsTest.php index 9a5bb56..1ce8b67 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionPermissionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionPermissionsTest.php @@ -41,7 +41,7 @@ function setUp() { $revision = clone $node; $revision->revision = 1; $revision->log = $this->randomName(32); - node_save($revision); + $revision->save(); $this->node_revisions[] = $revision; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index 5a40510..0fe1a3f 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -46,7 +46,7 @@ function setUp() { // Create revision with random title and body and update variables. $this->drupalCreateNode($settings); - $node = node_load($node->nid); // Make sure we get revision information. + $node = entity_load('node', $node->nid); // Make sure we get revision information. $settings = get_object_vars($node); $settings['isDefaultRevision'] = TRUE; @@ -85,7 +85,7 @@ function testRevisions() { $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => 'Basic page', '%title' => $nodes[1]->label(), '%revision-date' => format_date($nodes[1]->revision_timestamp))), t('Revision reverted.')); - $reverted_node = node_load($node->nid); + $reverted_node = entity_load('node', $node->nid); $this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); // Confirm that this is not the default version. @@ -123,7 +123,7 @@ function testRevisions() { // Save this as a non-default revision. $new_node_revision->revision = TRUE; $new_node_revision->isDefaultRevision = FALSE; - node_save($new_node_revision); + $new_node_revision->save(); $this->drupalGet("node/$node->nid"); $this->assertNoText($new_body, 'Revision body text is not present on default version of node.'); @@ -165,7 +165,7 @@ function testNodeRevisionWithoutLogMessage() { $node->save(); $this->drupalGet('node/' . $node->nid); $this->assertText($new_title, 'New node title appears on the page.'); - $node_revision = node_load($node->nid, TRUE); + $node_revision = entity_load('node', $node->nid, TRUE); $this->assertEqual($node_revision->log, $log, 'After an existing node revision is re-saved without a log message, the original log message is preserved.'); // Create another node with an initial log message. @@ -183,7 +183,7 @@ function testNodeRevisionWithoutLogMessage() { $node->save(); $this->drupalGet('node/' . $node->nid); $this->assertText($new_title, 'New node title appears on the page.'); - $node_revision = node_load($node->nid, TRUE); + $node_revision = entity_load('node', $node->nid, TRUE); $this->assertTrue(empty($node_revision->log), 'After a new node revision is saved with an empty log message, the log message for the node is empty.'); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php index f269bf3..216ba25 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php @@ -63,7 +63,7 @@ function testImport() { $node->save(); // Test the import. - $node_by_nid = node_load($test_nid); + $node_by_nid = entity_load('node', $test_nid); $this->assertTrue($node_by_nid, 'Node load by node ID.'); $node_by_title = $this->drupalGetNodeByTitle($title); @@ -153,7 +153,7 @@ function testDeterminingChanges() { $this->assertEqual($node->label(), 'updated_presave_update', 'Changes have been determined.'); // Test the static node load cache to be cleared. - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); $this->assertEqual($node->label(), 'updated_presave', 'Static cache has been cleared.'); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index 0b5f81d..473a40d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -40,7 +40,7 @@ function testNodeTokenReplacement() { $node = $this->drupalCreateNode($settings); // Load node so that the body and summary fields are structured properly. - $node = node_load($node->nid); + $node = entity_load('node', $node->nid); $instance = field_info_instance('node', 'body', $node->type); // Generate and test sanitized tokens. diff --git a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php index 8d4e0fe..10cb0cb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php @@ -122,14 +122,14 @@ function testPageAuthoredBy() { // authorship to the anonymous user (uid 0). $edit['name'] = ''; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); - $node = node_load($node->nid, TRUE); + $node = entity_load('node', $node->nid, TRUE); $this->assertIdentical($node->uid, '0', 'Node authored by anonymous user.'); // Change the authored by field to another user's name (that is not // logged in). $edit['name'] = $this->web_user->name; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); - $node = node_load($node->nid, TRUE); + $node = entity_load('node', $node->nid, TRUE); $this->assertIdentical($node->uid, $this->web_user->uid, 'Node authored by normal user.'); // Check that normal users cannot change the authored by information. diff --git a/core/modules/node/lib/Drupal/node/Tests/PageViewTest.php b/core/modules/node/lib/Drupal/node/Tests/PageViewTest.php index 460eb25..b47131b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PageViewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PageViewTest.php @@ -22,7 +22,7 @@ public static function getInfo() { function testPageView() { // Create a node to view. $node = $this->drupalCreateNode(); - $this->assertTrue(node_load($node->nid), 'Node created.'); + $this->assertTrue(entity_load('node', $node->nid), 'Node created.'); // Try to edit with anonymous user. $html = $this->drupalGet("node/$node->nid/edit"); diff --git a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php index ffdca5b..c9c3126 100644 --- a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php @@ -26,7 +26,7 @@ function testSummaryLength() { 'promote' => 1, ); $node = $this->drupalCreateNode($settings); - $this->assertTrue(node_load($node->nid), 'Node created.'); + $this->assertTrue(entity_load('node', $node->nid), 'Node created.'); // Create user with permission to view the node. $web_user = $this->drupalCreateUser(array('access content', 'administer content types')); diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index 2ca2d3e..61931cb 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -320,7 +320,7 @@ function node_mass_update($nodes, $updates) { * @see node_mass_update() */ function _node_mass_update_helper($nid, $updates) { - $node = node_load($nid, TRUE); + $node = entity_load('node', $nid, TRUE); // For efficiency manually save the original node before applying any changes. $node->original = clone $node; foreach ($updates as $name => $value) { @@ -518,7 +518,7 @@ function node_admin_nodes() { ->addTag('node_access') ->execute() ->fetchCol(); - $nodes = node_load_multiple($nids); + $nodes = entity_load_multiple('node', $nids); // Prepare the list of nodes. $languages = language_list(LANGUAGE_ALL); @@ -710,7 +710,7 @@ function node_multiple_delete_confirm($form, &$form_state, $nodes) { */ function node_multiple_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - node_delete_multiple(array_keys($form_state['values']['nodes'])); + entity_delete_multiple('node', array_keys($form_state['values']['nodes'])); $count = count($form_state['values']['nodes']); watchdog('content', 'Deleted @count posts.', array('@count' => $count)); drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.')); diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 113cc3d..c21e24c 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -58,8 +58,8 @@ * - hook_entity_update() (all) * - hook_node_access_records() (all) * - hook_node_access_records_alter() (all) - * - Loading a node (calling node_load(), node_load_multiple(), entity_load() - * or entity_load_multiple() with $entity_type of 'node'): + * - Loading a node (entity_load() or entity_load_multiple() with $entity_type + * of 'node'): * - Node and revision information is read from database. * - hook_load() (node-type-specific) * - field_attach_load_revision() and field_attach_load() @@ -87,7 +87,7 @@ * - hook_entity_view() (all) * - hook_node_view_alter() (all) * - hook_entity_view_alter() (all) - * - Deleting a node (calling node_delete() or node_delete_multiple()): + * - Deleting a node (calling entity_delete() or entity_delete_multiple()): * - Node is loaded (see Loading section above) * - hook_delete() (node-type-specific) * - hook_node_predelete() (all) @@ -453,7 +453,7 @@ function hook_node_operations() { /** * Act before node deletion. * - * This hook is invoked from node_delete_multiple() after the type-specific + * This hook is invoked from entity_delete_multiple() after the type-specific * hook_delete() has been invoked, but before hook_entity_predelete() and * field_attach_delete() are called, and before the node is removed from the * node table in the database. @@ -462,7 +462,7 @@ function hook_node_operations() { * The node that is about to be deleted. * * @see hook_node_predelete() - * @see node_delete_multiple() + * @see entity_delete_multiple() * @ingroup node_api_hooks */ function hook_node_predelete(Drupal\node\Node $node) { @@ -474,14 +474,14 @@ function hook_node_predelete(Drupal\node\Node $node) { /** * Respond to node deletion. * - * This hook is invoked from node_delete_multiple() after field_attach_delete() + * This hook is invoked from entity_delete_multiple() after field_attach_delete() * has been called and after the node has been removed from the database. * * @param Drupal\node\Node $node * The node that has been deleted. * * @see hook_node_predelete() - * @see node_delete_multiple() + * @see entity_delete_multiple() * @ingroup node_api_hooks */ function hook_node_delete(Drupal\node\Node $node) { @@ -665,7 +665,7 @@ function hook_node_prepare(Drupal\node\Node $node) { /** * Act on a node being displayed as a search result. * - * This hook is invoked from node_search_execute(), after node_load() + * This hook is invoked from node_search_execute(), after entity_load() * and node_view() have been called. * * @param Drupal\node\Node $node @@ -740,7 +740,7 @@ function hook_node_update(Drupal\node\Node $node) { /** * Act on a node being indexed for searching. * - * This hook is invoked during search indexing, after node_load(), and after + * This hook is invoked during search indexing, after entity_load(), and after * the result of node_view() is added as $node->rendered to the node object. * * @param Drupal\node\Node $node @@ -1056,7 +1056,7 @@ function hook_node_type_delete($info) { * This hook is invoked only on the module that defines the node's content type * (use hook_node_delete() to respond to all node deletions). * - * This hook is invoked from node_delete_multiple() after the node has been + * This hook is invoked from entity_delete_multiple() after the node has been * removed from the node table in the database, before hook_node_delete() is * invoked, and before field_attach_delete() is called. * @@ -1283,7 +1283,7 @@ function hook_validate(Drupal\node\Node $node, $form, &$form_state) { * add to the default display. * * @param Drupal\node\Node $node - * The node to be displayed, as returned by node_load(). + * The node to be displayed, as returned by entity_load(). * @param $view_mode * View mode, e.g. 'full', 'teaser', ... * diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 2dd1b57..ae2f202 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -138,7 +138,7 @@ function node_help($path, $arg) { return '

    ' . 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 .= '
    '; - $output .= theme('username', array('account' => user_load($node->uid))); + $output .= theme('username', array('account' => entity_load('user', $node->uid))); $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' => '', '#tree' => TRUE); - $accounts = user_load_multiple(array_keys(array_filter($edit['accounts']))); + $accounts = entity_load_multiple('user', array_keys(array_filter($edit['accounts']))); foreach ($accounts as $uid => $account) { // Prevent user 1 from being canceled. if ($uid <= 1) { @@ -2665,7 +2618,7 @@ function user_multiple_cancel_confirm_submit($form, &$form_state) { unset($admin_form_state['values']['user_cancel_confirm']); // The $user global is not a complete user entity, so load the full // entity. - $admin_form_state['values']['_account'] = user_load($user->uid); + $admin_form_state['values']['_account'] = entity_load('user', $user->uid); user_cancel_confirm_form_submit(array(), $admin_form_state); } else { @@ -2998,7 +2951,7 @@ function user_block_user_action(&$entity, $context = array()) { else { $uid = $GLOBALS['user']->uid; } - $account = user_load($uid); + $account = entity_load('user', $uid); $account->status = 0; $account->save(); watchdog('action', 'Blocked user %name.', array('%name' => $account->name)); diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 90d804e..566be01 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -107,7 +107,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a } // A different user is already logged in on the computer. else { - $reset_link_account = user_load($uid); + $reset_link_account = entity_load('user', $uid); if (!empty($reset_link_account)) { drupal_set_message(t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please logout and try using the link again.', array('%other_user' => $user->name, '%resetting_user' => $reset_link_account->name, '!logout' => url('user/logout')))); @@ -123,7 +123,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a // 86400 seconds. $timeout = variable_get('user_password_reset_timeout', 86400); $current = REQUEST_TIME; - $account = user_load($uid); + $account = entity_load('user', $uid); // Verify that the user exists and is active. if ($timestamp <= $current && $account && $account->status) { // No time out for first time login. diff --git a/core/modules/user/user.tokens.inc b/core/modules/user/user.tokens.inc index bc37434..f8d0e4a 100644 --- a/core/modules/user/user.tokens.inc +++ b/core/modules/user/user.tokens.inc @@ -123,7 +123,7 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr } if ($type == 'current-user') { - $account = user_load($GLOBALS['user']->uid); + $account = entity_load('user', $GLOBALS['user']->uid); $replacements += token_generate('user', $tokens, array('user' => $account), $options); } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 4eeb8d6..45075d0 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -263,7 +263,7 @@ function standard_install() { 'langcode' => language_default()->langcode, 'help' => $help, )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); $field = array( 'field_name' => 'field_' . $vocabulary->machine_name,