diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index d03d645..6fd5800 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -37,7 +37,7 @@ * @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); + * $node = Node::load(1); * $user = user_load(1); * * // [date:...] tokens use the current date automatically. diff --git a/core/modules/action/src/Tests/BulkFormTest.php b/core/modules/action/src/Tests/BulkFormTest.php index 024780b..0184c0d 100644 --- a/core/modules/action/src/Tests/BulkFormTest.php +++ b/core/modules/action/src/Tests/BulkFormTest.php @@ -9,6 +9,7 @@ use Drupal\simpletest\WebTestBase; use Drupal\views\Views; +use Drupal\node\Entity\Node; /** * Tests the views bulk form test. @@ -29,6 +30,8 @@ class BulkFormTest extends WebTestBase { * Tests the bulk form. */ public function testBulkForm() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + // First, test an empty bulk form with the default style plugin to make sure // the empty region is rendered correctly. $this->drupalGet('test_bulk_form_empty'); @@ -66,14 +69,14 @@ public function testBulkForm() { $this->drupalPostForm(NULL, $edit, t('Apply')); foreach ($nodes as $node) { - $changed_node = node_load($node->id()); + $changed_node = Node::load($node->id()); $this->assertTrue($changed_node->isSticky(), format_string('Node @nid got marked as sticky.', array('@nid' => $node->id()))); } $this->assertText('Make content sticky was applied to 10 items.'); // Unpublish just one node. - $node = node_load($nodes[0]->id()); + $node = Node::load($nodes[0]->id()); $this->assertTrue($node->isPublished(), 'The node is published.'); $edit = array('node_bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action'); @@ -82,11 +85,13 @@ public function testBulkForm() { $this->assertText('Unpublish content was applied to 1 item.'); // Load the node again. - $node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertFalse($node->isPublished(), 'A single node has been unpublished.'); // The second node should still be published. - $node = node_load($nodes[1]->id(), TRUE); + $node_storage->resetCache(array($nodes[1]->id())); + $node = Node::load($nodes[1]->id()); $this->assertTrue($node->isPublished(), 'An unchecked node is still published.'); // Set up to include just the sticky actions. diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 861ed73..1dff053 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -17,6 +17,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Template\Attribute; +use Drupal\node\Entity\Node; /** * Implements hook_help(). @@ -332,7 +333,7 @@ function book_node_prepare_form(NodeInterface $node, $operation, FormStateInterf * @see node_delete_confirm() */ function book_form_node_delete_confirm_alter(&$form, FormStateInterface $form_state) { - $node = node_load($form['nid']['#value']); + $node = Node::load($form['nid']['#value']); if (isset($node->book) && $node->book['has_children']) { $form['book_warning'] = array( diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index 4c2fd14..5876949 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -13,6 +13,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Drupal\node\Entity\Node; /** * Provides a 'Book navigation' block. @@ -132,7 +133,7 @@ public function build() { // 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 = Node::load($book['nid']); $book['access'] = $book_node->access('view'); $pseudo_tree[0]['link'] = $book; $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree); diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index 2e6e851..473e38d 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\simpletest\WebTestBase; +use Drupal\node\Entity\Node; /** * Create a book, add pages, and test book interface. @@ -383,6 +384,7 @@ function testNavigationBlockOnAccessModuleEnabled() { * Tests the access for deleting top-level book nodes. */ function testBookDelete() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $nodes = $this->createBook(); $this->drupalLogin($this->admin_user); $edit = array(); @@ -391,7 +393,8 @@ function testBookDelete() { $this->drupalGet('node/' . $this->book->id() . '/outline/remove'); $this->assertResponse('403', 'Deleting top-level book node properly forbidden.'); $this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove')); - $node4 = node_load($nodes[4]->id(), TRUE); + $node_storage->resetCache(array($nodes[4]->id())); + $node4 = Node::load($nodes[4]->id()); $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.'); // Delete all child book nodes and retest top-level node deletion. @@ -400,7 +403,8 @@ function testBookDelete() { } entity_delete_multiple('node', $nids); $this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove')); - $node = node_load($this->book->id(), TRUE); + $node_storage->resetCache(array($this->book->id())); + $node = Node::load($this->book->id()); $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.'); } diff --git a/core/modules/comment/src/Controller/CommentController.php b/core/modules/comment/src/Controller/CommentController.php index af415d0..d67470d 100644 --- a/core/modules/comment/src/Controller/CommentController.php +++ b/core/modules/comment/src/Controller/CommentController.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Drupal\node\Entity\Node; /** * Controller for the comment entity. @@ -285,7 +286,7 @@ public function renderNewCommentsNodeLinks(Request $request) { $links = array(); foreach ($nids as $nid) { - $node = node_load($nid); + $node = Node::load($nid); $new = $this->commentManager->getCountNewComments($node); $page_number = $this->entityManager()->getStorage('comment') ->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node); diff --git a/core/modules/comment/src/Tests/CommentPagerTest.php b/core/modules/comment/src/Tests/CommentPagerTest.php index 9853d1c..15c6f87 100644 --- a/core/modules/comment/src/Tests/CommentPagerTest.php +++ b/core/modules/comment/src/Tests/CommentPagerTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\comment\CommentManagerInterface; +use Drupal\node\Entity\Node; /** * Tests paging of comments and their settings. @@ -239,7 +240,7 @@ function testCommentNewPageIndicator() { 6 => 0, // Page of comment 0 ); - $node = node_load($node->id()); + $node = Node::load($node->id()); foreach ($expected_pages as $new_replies => $expected_page) { $returned_page = \Drupal::entityManager()->getStorage('comment') ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node); @@ -258,7 +259,7 @@ function testCommentNewPageIndicator() { ); \Drupal::entityManager()->getStorage('node')->resetCache(array($node->id())); - $node = node_load($node->id()); + $node = Node::load($node->id()); foreach ($expected_pages as $new_replies => $expected_page) { $returned_page = \Drupal::entityManager()->getStorage('comment') ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node); diff --git a/core/modules/comment/src/Tests/CommentStatisticsTest.php b/core/modules/comment/src/Tests/CommentStatisticsTest.php index 6b7bf01..89e29f2 100644 --- a/core/modules/comment/src/Tests/CommentStatisticsTest.php +++ b/core/modules/comment/src/Tests/CommentStatisticsTest.php @@ -9,6 +9,7 @@ use Drupal\comment\CommentManagerInterface; use Drupal\comment\Entity\Comment; +use Drupal\node\Entity\Node; /** * Tests comment statistics on nodes. @@ -36,6 +37,7 @@ protected function setUp() { * Tests the node comment statistics. */ function testCommentNodeCommentStatistics() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Set comments to have subject and preview disabled. $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_DISABLED); @@ -45,7 +47,7 @@ function testCommentNodeCommentStatistics() { $this->drupalLogout(); // Checks the initial values of node comment statistics with no comment. - $node = node_load($this->node->id()); + $node = Node::load($this->node->id()); $this->assertEqual($node->get('comment')->last_comment_timestamp, $this->node->getCreatedTime(), 'The initial value of node last_comment_timestamp is the node created date.'); $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.'); $this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user->id(), 'The initial value of node last_comment_uid is the node uid.'); @@ -57,8 +59,9 @@ function testCommentNodeCommentStatistics() { $this->postComment($this->node, $comment_text); // 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->id(), TRUE); + // The node cache needs to be reset before reload. + $node_storage->resetCache(array($this->node->id())); + $node = Node::load($this->node->id()); $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is NULL.'); $this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is the comment #1 uid.'); $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is 1.'); @@ -80,8 +83,9 @@ function testCommentNodeCommentStatistics() { // 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->id(), TRUE); + // The node needs to be reloaded with the cache reset. + $node_storage->resetCache(array($this->node->id())); + $node = Node::load($this->node->id()); $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.'); $this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is still the comment #1 uid.'); $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is still 1.'); @@ -101,8 +105,9 @@ function testCommentNodeCommentStatistics() { $comment_loaded = Comment::load($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->id(), TRUE); + // The node needs to be reloaded with the cache reset. + $node_storage->resetCache(array($this->node->id())); + $node = Node::load($this->node->id()); $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->getAuthorName(), 'The value of node last_comment_name is the name of the anonymous user.'); $this->assertEqual($node->get('comment')->last_comment_uid, 0, 'The value of node last_comment_uid is zero.'); $this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.'); diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php index 97335f8..76f028d 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Xss; use Drupal\comment\Entity\Comment; +use Drupal\node\Entity\Node; /** * Generates text using placeholders for dummy content to check comment token @@ -94,7 +95,7 @@ function testCommentTokenReplacement() { } // Load node so comment_count gets computed. - $node = node_load($node->id()); + $node = Node::load($node->id()); // Generate comment tokens for the node (it has 2 comments, both new). $tests = array(); diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php index 3b1cc5e..6536eea 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAutoCreateTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\simpletest\WebTestBase; +use Drupal\node\Entity\Node; /** * Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget. @@ -103,7 +104,7 @@ public function testAutoCreate() { $result = $query->execute(); $this->assertTrue($result, 'Referenced node was created.'); $referenced_nid = key($result); - $referenced_node = node_load($referenced_nid); + $referenced_node = Node::load($referenced_nid); // Assert the referenced node is associated with referencing node. $result = \Drupal::entityQuery('node') @@ -111,7 +112,7 @@ public function testAutoCreate() { ->execute(); $referencing_nid = key($result); - $referencing_node = node_load($referencing_nid); + $referencing_node = Node::load($referencing_nid); $this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.'); // Now try to view the node and check that the referenced node is shown. diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index 1b11125..3448f0c 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\node\Entity\Node; /** * Tests the display of file fields in node and views. @@ -54,7 +55,9 @@ function testNodeDisplay() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the default formatter is displaying with the file name. - $node = node_load($nid, TRUE); + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $file_link = array( '#theme' => 'file_link', diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php index 865317a..846f8ce 100644 --- a/core/modules/file/src/Tests/FileFieldPathTest.php +++ b/core/modules/file/src/Tests/FileFieldPathTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\node\Entity\Node; + /** * Tests that files are uploaded to proper locations. * @@ -17,6 +19,7 @@ class FileFieldPathTest extends FileFieldTestBase { * Tests the normal formatter display on node display. */ function testUploadPath() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $this->createFileField($field_name, 'node', $type_name); @@ -26,7 +29,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); @@ -37,7 +41,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id, TRUE); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); @@ -49,7 +54,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. diff --git a/core/modules/file/src/Tests/FileFieldRSSContentTest.php b/core/modules/file/src/Tests/FileFieldRSSContentTest.php index 5da2242..1c5621d 100644 --- a/core/modules/file/src/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/src/Tests/FileFieldRSSContentTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\node\Entity\Node; + /** * Ensure that files added to nodes appear correctly in RSS feeds. * @@ -25,6 +27,7 @@ class FileFieldRSSContentTest extends FileFieldTestBase { * Tests RSS enclosure formatter display for RSS feeds. */ function testFileFieldRSSContent() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $field_settings = array( @@ -58,7 +61,8 @@ function testFileFieldRSSContent() { $nid = $this->uploadNodeFile($test_file, $field_name, $node->id()); // Get the uploaded file from the node. - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index b45b200..d3c3efa 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\node\Entity\Node; + /** * Tests creating and deleting revisions with files attached. * @@ -25,6 +27,7 @@ class FileFieldRevisionTest extends FileFieldTestBase { * should be deleted also. */ function testRevisions() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); @@ -37,7 +40,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file_r1 = file_load($node->{$field_name}->target_id); $node_vid_r1 = $node->getRevisionId(); $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); @@ -46,7 +50,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file_r2 = file_load($node->{$field_name}->target_id); $node_vid_r2 = $node->getRevisionId(); $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); @@ -64,7 +69,8 @@ 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->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file_r3 = file_load($node->{$field_name}->target_id); $node_vid_r3 = $node->getRevisionId(); $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.'); @@ -72,7 +78,8 @@ function testRevisions() { // Revert to the first revision and check that the original file is active. $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file_r4 = file_load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.'); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 8533a5c..b1eed2d 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -11,6 +11,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; +use Drupal\node\Entity\Node; /** * Provides methods specifically for testing File module's field handling. @@ -144,6 +145,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $nid = $nid_or_type; } else { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Add a new node. $extras['type'] = $nid_or_type; $node = $this->drupalCreateNode($extras); @@ -151,7 +153,8 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, // Save at least one revision to better simulate a real site. $node->setNewRevision(); $node->save(); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $this->assertNotEqual($nid, $node->getRevisionId(), 'Node revision exists.'); } diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index bc910e0..225f51f 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldConfig; +use Drupal\node\Entity\Node; /** * Tests validation functions such as file type, max file size, max size per @@ -24,6 +25,7 @@ class FileFieldValidateTest extends FileFieldTestBase { * Tests the required property on file fields. */ function testRequired() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $storage = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); @@ -41,7 +43,8 @@ function testRequired() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name))); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); @@ -59,7 +62,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); @@ -69,6 +73,7 @@ function testRequired() { * Tests the max file size validator. */ function testFileMaxSize() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); @@ -89,7 +94,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); @@ -105,7 +111,8 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); @@ -115,6 +122,7 @@ function testFileMaxSize() { * Tests file extension checking. */ function testFileExtension() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); @@ -127,7 +135,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); @@ -145,7 +154,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index 5cc7ab7..d353327 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -9,6 +9,7 @@ use Drupal\comment\Entity\Comment; use Drupal\field\Entity\FieldConfig; +use Drupal\node\Entity\Node; /** * Tests the file field widget, single and multi-valued, with and without AJAX, @@ -29,6 +30,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { * Tests upload and remove buttons for a single-valued File field. */ function testSingleValuedWidget() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); @@ -41,7 +43,8 @@ function testSingleValuedWidget() { // @todo This only tests a 'nojs' submission, because drupalPostAjaxForm() // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); @@ -74,7 +77,8 @@ function testSingleValuedWidget() { // Save the node and ensure it does not have the file. $this->drupalPostForm(NULL, array(), t('Save and keep published')); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.'); } } @@ -83,6 +87,7 @@ function testSingleValuedWidget() { * Tests upload and remove buttons for multiple multi-valued File fields. */ function testMultiValuedWidget() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; // Use explicit names instead of random names for those fields, because of a // bug in drupalPostForm() with multiple file uploads in one form, where the @@ -191,7 +196,8 @@ function testMultiValuedWidget() { $matches = array(); preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $this->assertTrue(empty($node->{$field_name}->target_id), 'Node was successfully saved without any files.'); } } @@ -200,6 +206,7 @@ function testMultiValuedWidget() { * Tests a file field with a "Private files" upload destination setting. */ function testPrivateFileSetting() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Grant the admin user required permissions. user_role_grant_permissions($this->admin_user->roles[0]->target_id, array('administer node fields')); @@ -214,7 +221,8 @@ function testPrivateFileSetting() { $edit = array('field_storage[settings][uri_scheme]' => 'private'); $this->drupalPostForm("admin/structure/types/manage/$type_name/fields/$field->id/storage", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index d1561cc..1e3dde0 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -34,6 +34,7 @@ protected function setUp() { * Tests file access for file uploaded to a private node. */ function testPrivateFile() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private')); @@ -45,7 +46,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_storage->resetCache(array($nid)); + $node = Node::load($nid); $node_file = file_load($node->{$field_name}->target_id); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 36fe888..84be5c6 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Component\Utility\String; +use Drupal\node\Entity\Node; /** * Generates text using placeholders for dummy content to check file token @@ -20,6 +21,7 @@ class FileTokenReplaceTest extends FileFieldTestBase { * Creates a file, then tests the tokens generated from it. */ function testFileTokenReplacement() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $token_service = \Drupal::token(); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); @@ -37,7 +39,8 @@ function testFileTokenReplacement() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Load the node and the file. - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); $file = file_load($node->{$field_name}->target_id); // Generate and test sanitized tokens. diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index 75b8843..b314686 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\image\ImageStyleInterface; +use Drupal\node\Entity\Node; /** * Tests creation, deletion, and editing of image styles and effects. @@ -296,7 +297,7 @@ 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 = Node::load($nid); // Get node field original image URI. $fid = $node->get($field_name)->target_id; @@ -430,7 +431,7 @@ function testConfigImport() { // 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 = Node::load($nid); // Get node field original image URI. $fid = $node->get($field_name)->target_id; diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 9cef633..7f41b98 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; use Drupal\file\Entity\File; +use Drupal\node\Entity\Node; /** * Tests setting up default images both to the field and field field. @@ -26,6 +27,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { * Tests CRUD for fields and fields fields with default images. */ public function testDefaultImages() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create files to use as the default images. $files = $this->drupalGetTestFiles('image'); // Create 10 files so the default image fids are not a single value. @@ -188,8 +190,9 @@ public function testDefaultImages() { ); // Reload the nodes and confirm the field field defaults are used. - $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); + $node_storage->resetCache(array($article->id(), $page->id())); + $article_built = $this->drupalBuildEntityView($article = Node::load($article->id())); + $page_built = $this->drupalBuildEntityView($page = Node::load($page->id())); $this->assertEqual( $article_built[$field_name]['#items'][0]->target_id, $default_images['field']->id(), @@ -224,8 +227,9 @@ public function testDefaultImages() { ); // Reload the nodes. - $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); + $node_storage->resetCache(array($article->id(), $page->id())); + $article_built = $this->drupalBuildEntityView($article = Node::load($article->id())); + $page_built = $this->drupalBuildEntityView($page = Node::load($page->id())); // Confirm the article uses the new default. $this->assertEqual( @@ -264,8 +268,9 @@ public function testDefaultImages() { ); // Reload the nodes. - $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); + $node_storage->resetCache(array($article->id(), $page->id())); + $article_built = $this->drupalBuildEntityView($article = Node::load($article->id())); + $page_built = $this->drupalBuildEntityView($page = Node::load($page->id())); // Confirm the article uses the new field (not field) default. $this->assertEqual( $article_built[$field_name]['#items'][0]->target_id, diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 0253aaf..eaf967a 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\node\Entity\Node; /** * Tests the display of image fields. @@ -46,6 +47,7 @@ function testImageFieldFormattersPrivate() { * Test image formatters on node display. */ function _testImageFieldFormatters($scheme) { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $this->createImageField($field_name, 'article', array('uri_scheme' => $scheme)); @@ -57,7 +59,8 @@ function _testImageFieldFormatters($scheme) { // Save node. $nid = $this->uploadNodeImage($test_image, $field_name, 'article'); - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); // Test that the default formatter is being used. $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); @@ -165,6 +168,7 @@ function _testImageFieldFormatters($scheme) { * Tests for image field settings. */ function testImageFieldSettings() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $test_image = current($this->drupalGetTestFiles('image')); list(, $test_image_extension) = explode('.', $test_image->filename); $field_name = strtolower($this->randomMachineName()); @@ -195,7 +199,8 @@ function testImageFieldSettings() { $this->assertFieldByName($field_name . '[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_storage->resetCache(array($nid)); + $node = Node::load($nid); $image_style = array( '#theme' => 'image_style', '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), @@ -266,6 +271,7 @@ function testImageFieldSettings() { * Test use of a default image with an image field. */ function testImageFieldDefaultImage() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create a new image field. $field_name = strtolower($this->randomMachineName()); $this->createImageField($field_name, 'article'); @@ -313,7 +319,8 @@ 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_storage->resetCache(array($nid)); + $node = Node::load($nid); $image = array( '#theme' => 'image', '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 09bc6f4..dfd5af6 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Menu\MenuLinkInterface; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\system\Entity\Menu; +use Drupal\node\Entity\Node; /** * Add a custom menu, add menu links to the custom menu and Tools menu, check @@ -93,7 +94,7 @@ function testMenu() { foreach ($this->items as $item) { // Paths were set as 'node/$nid'. - $node = node_load($item->getRouteParameters()['node']); + $node = Node::load($item->getRouteParameters()['node']); $this->verifyMenuLink($item, $node); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBookTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBookTest.php index 33f36b2..5acd3e8 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBookTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBookTest.php @@ -9,6 +9,7 @@ use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\node\Entity\Node; /** * Upgrade book structure. @@ -51,7 +52,7 @@ protected function setUp() { * Tests the Drupal 6 book structure to Drupal 8 migration. */ public function testBook() { - $nodes = node_load_multiple(array(4, 5, 6, 7, 8)); + $nodes = Node::loadMultiple(array(4, 5, 6, 7, 8)); $this->assertEqual($nodes[4]->book['bid'], 4); $this->assertEqual($nodes[4]->book['pid'], 0); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTest.php index 517e30b..e6a26f0 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTest.php @@ -9,6 +9,7 @@ use Drupal\migrate\MigrateExecutable; use Drupal\Core\Database\Database; +use Drupal\node\Entity\Node; /** * Node content migration. @@ -36,7 +37,7 @@ protected function setUp() { * Test node migration from Drupal 6 to 8. */ public function testNode() { - $node = node_load(1); + $node = Node::load(1); $this->assertEqual($node->id(), 1, 'Node 1 loaded.'); $this->assertEqual($node->body->value, 'test'); $this->assertEqual($node->body->format, 'filtered_html'); @@ -70,7 +71,7 @@ public function testNode() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $node = node_load(1); + $node = Node::load(1); $this->assertEqual($node->getTitle(), 'New node title'); // Test a multi-column fields are correctly upgraded. $this->assertEqual($node->body->value, 'test'); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateTermNodeTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateTermNodeTest.php index dd3d421..cd51592 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateTermNodeTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateTermNodeTest.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Tests\d6; use Drupal\migrate\MigrateExecutable; +use Drupal\node\Entity\Node; /** * Upgrade taxonomy term node associations. @@ -33,7 +34,9 @@ protected function setUp() { * Tests the Drupal 6 term-node association to Drupal 8 migration. */ public function testTermNode() { - $nodes = node_load_multiple(array(1, 2), TRUE); + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + $node_storage->resetCache(array(1, 2)); + $nodes = Node::loadMultiple(array(1, 2)); $node = $nodes[1]; $this->assertEqual(count($node->vocabulary_1_i_0_), 1); $this->assertEqual($node->vocabulary_1_i_0_[0]->target_id, 1); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUploadTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUploadTest.php index 76fdc94..ca1ee62 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUploadTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUploadTest.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Tests\d6; use Drupal\migrate\MigrateExecutable; +use Drupal\node\Entity\Node; /** * Migrate association data between nodes and files. @@ -31,7 +32,9 @@ protected function setUp() { * Test upload migration from Drupal 6 to Drupal 8. */ function testUpload() { - $nodes = node_load_multiple(array(1, 2), TRUE); + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + $node_storage->resetCache(array(1, 2)); + $nodes = Node::loadMultiple(array(1, 2)); $node = $nodes[1]; $this->assertEqual(count($node->upload), 1); $this->assertEqual($node->upload[0]->target_id, 1); diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index b0a806d..97f2b65 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -7,6 +7,7 @@ use Drupal\Core\Language\Language; use Drupal\node\NodeInterface; +use Drupal\node\Entity\Node; /** * Updates all nodes in the passed-in array with the passed-in field values. @@ -52,7 +53,7 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load } else { if ($load && !$revisions) { - $nodes = entity_load_multiple('node', $nodes); + $nodes = Node::loadMultiple($nodes); } foreach ($nodes as $node) { if ($load && $revisions) { @@ -123,7 +124,7 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $load, $r $node = array_shift($context['sandbox']['nodes']); if ($load) { $node = $revisions ? - entity_revision_load('node', $node) : entity_load('node', $node); + entity_revision_load('node', $node) : Node::load($node); } $node = _node_mass_update_helper($node, $updates); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 159a230..c9f66be 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -845,7 +845,7 @@ function node_get_recent($number = 10) { ->addTag('node_access') ->execute(); - $nodes = node_load_multiple($nids); + $nodes = Node::loadMultiple($nids); return $nodes ? $nodes : array(); } @@ -872,7 +872,7 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) { * 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 Node::loadMultiple(). * @param $view_mode * (optional) View mode, e.g., 'full', 'teaser'... Defaults to 'teaser.' * @param $langcode @@ -1238,6 +1238,7 @@ function node_access_needs_rebuild($rebuild = NULL) { * @see node_access_needs_rebuild() */ function node_access_rebuild($batch_mode = FALSE) { + $node_storage = \Drupal::entityManager()->getStorage('node'); $access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node'); $access_control_handler->deleteGrants(); // Only recalculate if the site is using a node_access module. @@ -1262,7 +1263,8 @@ function node_access_rebuild($batch_mode = FALSE) { $entity_query->sort('nid', 'DESC'); $nids = $entity_query->execute(); foreach ($nids as $nid) { - $node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $node = Node::load($nid); // To preserve database integrity, only write grants if the node // loads successfully. if (!empty($node)) { @@ -1293,6 +1295,7 @@ function node_access_rebuild($batch_mode = FALSE) { * An array of contextual key/value information for rebuild batch process. */ function _node_access_rebuild_batch_operation(&$context) { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); if (empty($context['sandbox'])) { // Initiate multistep processing. $context['sandbox']['progress'] = 0; @@ -1307,7 +1310,8 @@ function _node_access_rebuild_batch_operation(&$context) { ->sort('nid', 'DESC') ->range(0, $limit) ->execute(); - $nodes = node_load_multiple($nids, TRUE); + $node_storage->resetCache($nids); + $nodes = Node::loadMultiple($nids); foreach ($nodes as $nid => $node) { // To preserve database integrity, only write grants if the node // loads successfully. diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php index 8cf1c04..dc62e9e 100644 --- a/core/modules/node/src/NodeViewBuilder.php +++ b/core/modules/node/src/NodeViewBuilder.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityViewBuilder; +use Drupal\node\Entity\Node; /** * Render controller for nodes. @@ -108,7 +109,7 @@ public static function renderLinks(array $element, array $context) { ); if (!$context['in_preview']) { - $entity = entity_load('node', $context['node_entity_id'])->getTranslation($context['langcode']); + $entity = Node::load($context['node_entity_id'])->getTranslation($context['langcode']); $links['node'] = self::buildLinks($entity, $context['view_mode']); // Allow other modules to alter the node links. diff --git a/core/modules/node/src/Plugin/views/argument/Nid.php b/core/modules/node/src/Plugin/views/argument/Nid.php index 06ea25d..2338508 100644 --- a/core/modules/node/src/Plugin/views/argument/Nid.php +++ b/core/modules/node/src/Plugin/views/argument/Nid.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\views\Plugin\views\argument\Numeric; +use Drupal\node\Entity\Node; /** * Argument handler to accept a node id. @@ -23,7 +24,7 @@ class Nid extends Numeric { public function titleQuery() { $titles = array(); - $nodes = node_load_multiple($this->value); + $nodes = Node::loadMultiple($this->value); foreach ($nodes as $node) { $titles[] = String::checkPlain($node->label()); } diff --git a/core/modules/node/src/Plugin/views/argument/Vid.php b/core/modules/node/src/Plugin/views/argument/Vid.php index 9c7d39e..6b5b1cd 100644 --- a/core/modules/node/src/Plugin/views/argument/Vid.php +++ b/core/modules/node/src/Plugin/views/argument/Vid.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\Connection; use Drupal\views\Plugin\views\argument\Numeric; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\node\Entity\Node; /** * Argument handler to accept a node revision id. @@ -63,7 +64,7 @@ public function titleQuery() { $nids[] = $result['nid']; } - $nodes = node_load_multiple(array_unique($nids)); + $nodes = Node::loadMultiple(array_unique($nids)); foreach ($results as $result) { $nodes[$result['nid']]->set('title', $result['title']); diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index 04aff57..1a725bc 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\row\RowPluginBase; +use Drupal\node\Entity\Node; /** * Plugin which performs a node_view on the resulting object @@ -80,7 +81,7 @@ public function preRender($values) { $nids[] = $row->{$this->field_alias}; } if (!empty($nids)) { - $this->nodes = node_load_multiple($nids); + $this->nodes = Node::loadMultiple($nids); } } diff --git a/core/modules/node/src/Tests/NodeAccessRecordsTest.php b/core/modules/node/src/Tests/NodeAccessRecordsTest.php index fc0141f..4b019c8 100644 --- a/core/modules/node/src/Tests/NodeAccessRecordsTest.php +++ b/core/modules/node/src/Tests/NodeAccessRecordsTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests hook_node_access_records when acquiring grants. * @@ -27,7 +29,7 @@ class NodeAccessRecordsTest extends NodeTestBase { function testNodeAccessRecords() { // Create an article node. $node1 = $this->drupalCreateNode(array('type' => 'article')); - $this->assertTrue(node_load($node1->id()), 'Article node created.'); + $this->assertTrue(Node::load($node1->id()), '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->id()))->fetchAll(); @@ -37,7 +39,7 @@ function testNodeAccessRecords() { // Create an unpromoted "Basic page" node. $node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0)); - $this->assertTrue(node_load($node2->id()), 'Unpromoted basic page node created.'); + $this->assertTrue(Node::load($node2->id()), '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->id()))->fetchAll(); @@ -47,7 +49,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->id()), 'Unpromoted, unpublished basic page node created.'); + $this->assertTrue(Node::load($node3->id()), '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->id()))->fetchAll(); @@ -57,7 +59,7 @@ function testNodeAccessRecords() { // Create a promoted "Basic page" node. $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); - $this->assertTrue(node_load($node4->id()), 'Promoted basic page node created.'); + $this->assertTrue(Node::load($node4->id()), '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/src/Tests/NodeFormButtonsTest.php b/core/modules/node/src/Tests/NodeFormButtonsTest.php index cc33ed8..a7a0dbe 100644 --- a/core/modules/node/src/Tests/NodeFormButtonsTest.php +++ b/core/modules/node/src/Tests/NodeFormButtonsTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests all the different buttons on the node form. * @@ -31,7 +33,7 @@ protected function setUp() { * Tests that the right buttons are displayed for saving nodes. */ function testNodeFormButtons() { - + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Login as administrative user. $this->drupalLogin($this->admin_user); @@ -45,7 +47,7 @@ function testNodeFormButtons() { $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); // Get the node. - $node_1 = node_load(1); + $node_1 = Node::load(1); $this->assertTrue($node_1->isPublished(), 'Node is published'); // Verify the buttons on a node edit form. @@ -55,13 +57,15 @@ function testNodeFormButtons() { // Save the node and verify it's still published after clicking // 'Save and keep published'. $this->drupalPostForm(NULL, $edit, t('Save and keep published')); - $node_1 = node_load(1, TRUE); + $node_storage->resetCache(array(1)); + $node_1 = Node::load(1); $this->assertTrue($node_1->isPublished(), 'Node is published'); // Save the node and verify it's unpublished after clicking // 'Save and unpublish'. $this->drupalPostForm('node/' . $node_1->id() . '/edit', $edit, t('Save and unpublish')); - $node_1 = node_load(1, TRUE); + $node_storage->resetCache(array(1)); + $node_1 = Node::load(1); $this->assertFalse($node_1->isPublished(), 'Node is unpublished'); // Verify the buttons on an unpublished node edit screen. @@ -79,7 +83,7 @@ function testNodeFormButtons() { // Create the node. $edit = array('title[0][value]' => $this->randomString()); $this->drupalPostForm('node/add/article', $edit, t('Save')); - $node_2 = node_load(2); + $node_2 = Node::load(2); $this->assertTrue($node_2->isPublished(), 'Node is published'); // Login as an administrator and unpublish the node that just @@ -87,7 +91,8 @@ function testNodeFormButtons() { $this->drupalLogout(); $this->drupalLogin($this->admin_user); $this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save and unpublish')); - $node_2 = node_load(2, TRUE); + $node_storage->resetCache(array(2)); + $node_2 = Node::load(2); $this->assertFalse($node_2->isPublished(), 'Node is unpublished'); // Login again as the normal user, save the node and verify @@ -95,7 +100,8 @@ function testNodeFormButtons() { $this->drupalLogout(); $this->drupalLogin($this->web_user); $this->drupalPostForm('node/' . $node_2->id() . '/edit', array(), t('Save')); - $node_2 = node_load(2, TRUE); + $node_storage->resetCache(array(2)); + $node_2 = Node::load(2); $this->assertFalse($node_2->isPublished(), 'Node is still unpublished'); $this->drupalLogout(); @@ -117,7 +123,7 @@ function testNodeFormButtons() { $this->drupalLogin($this->web_user); $edit = array('title[0][value]' => $this->randomString()); $this->drupalPostForm('node/add/article', $edit, t('Save')); - $node_3 = node_load(3); + $node_3 = Node::load(3); $this->assertFalse($node_3->isPublished(), 'Node is unpublished'); } diff --git a/core/modules/node/src/Tests/NodeLoadMultipleTest.php b/core/modules/node/src/Tests/NodeLoadMultipleTest.php index 3cea6a1..afb1d30 100644 --- a/core/modules/node/src/Tests/NodeLoadMultipleTest.php +++ b/core/modules/node/src/Tests/NodeLoadMultipleTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests the loading of multiple nodes. * @@ -15,7 +17,7 @@ class NodeLoadMultipleTest extends NodeTestBase { /** - * Enable Views to test the frontpage against node_load_multiple() results. + * Enable Views to test the frontpage against Node::loadMultiple() results. * * @var array */ @@ -51,7 +53,7 @@ function testNodeMultipleLoad() { $this->assertTrue($count == 2, format_string('@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 = Node::loadMultiple(array(1, 2, 4)); $count = count($nodes); $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', array('@count' => $count))); $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array'); diff --git a/core/modules/node/src/Tests/NodeRevisionsAllTest.php b/core/modules/node/src/Tests/NodeRevisionsAllTest.php index 58712f1..8ea1fcb 100644 --- a/core/modules/node/src/Tests/NodeRevisionsAllTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsAllTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Create a node with revisions and test viewing, saving, reverting, and * deleting revisions for user with access to all. @@ -20,7 +22,7 @@ class NodeRevisionsAllTest extends NodeTestBase { protected function setUp() { parent::setUp(); - + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create and log in user. $web_user = $this->drupalCreateUser( array( @@ -59,7 +61,8 @@ protected function setUp() { $node->setNewRevision(); $node->save(); - $node = node_load($node->id(), TRUE); // Make sure we get revision information. + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); // Make sure we get revision information. $nodes[] = clone $node; } @@ -71,6 +74,7 @@ protected function setUp() { * Checks node revision operations. */ function testRevisions() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $nodes = $this->nodes; $logs = $this->revisionLogs; @@ -112,7 +116,8 @@ function testRevisions() { '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()) )), 'Revision reverted.'); - $reverted_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $reverted_node = Node::load($node->id()); $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); // Confirm that this is not the current version. diff --git a/core/modules/node/src/Tests/NodeRevisionsTest.php b/core/modules/node/src/Tests/NodeRevisionsTest.php index 5949824..630bdd6 100644 --- a/core/modules/node/src/Tests/NodeRevisionsTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Create a node with revisions and test viewing, saving, reverting, and * deleting revisions for users with access for this content type. @@ -59,7 +61,7 @@ protected function setUp() { $node->setNewRevision(); $node->save(); - $node = node_load($node->id()); // Make sure we get revision information. + $node = Node::load($node->id()); // Make sure we get revision information. $nodes[] = clone $node; } @@ -71,6 +73,7 @@ protected function setUp() { * Checks node revision related operations. */ function testRevisions() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $nodes = $this->nodes; $logs = $this->revisionLogs; @@ -95,7 +98,8 @@ 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]->getRevisionCreationTime()))), 'Revision reverted.'); - $reverted_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $reverted_node = Node::load($node->id()); $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); // Confirm that this is not the default version. @@ -157,6 +161,7 @@ function testRevisions() { * Checks that revisions are correctly saved without log messages. */ function testNodeRevisionWithoutLogMessage() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create a node with an initial log message. $revision_log = $this->randomMachineName(10); $node = $this->drupalCreateNode(array('revision_log' => $revision_log)); @@ -175,7 +180,8 @@ function testNodeRevisionWithoutLogMessage() { $node->save(); $this->drupalGet('node/' . $node->id()); $this->assertText($new_title, 'New node title appears on the page.'); - $node_revision = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node_revision = Node::load($node->id()); $this->assertEqual($node_revision->revision_log->value, $revision_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 revision log message. @@ -193,7 +199,8 @@ function testNodeRevisionWithoutLogMessage() { $node->save(); $this->drupalGet('node/' . $node->id()); $this->assertText($new_title, 'New node title appears on the page.'); - $node_revision = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node_revision = Node::load($node->id()); $this->assertTrue(empty($node_revision->revision_log->value), '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/src/Tests/NodeRevisionsUiTest.php b/core/modules/node/src/Tests/NodeRevisionsUiTest.php index c9a4a36..f2c991f 100644 --- a/core/modules/node/src/Tests/NodeRevisionsUiTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsUiTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests the UI for controlling node revision behavior. * @@ -35,6 +37,7 @@ protected function setUp() { * Checks that unchecking 'Create new revision' works when editing a node. */ function testNodeFormSaveWithoutRevision() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Set page revision setting 'create new revision'. This will mean new // revisions are created by default when the node is edited. @@ -54,7 +57,8 @@ function testNodeFormSaveWithoutRevision() { $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Load the node again and check the revision is the same as before. - $node_revision = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node_revision = Node::load($node->id(), TRUE); $this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created."); // Verify the checkbox is checked on the node edit form. @@ -66,7 +70,8 @@ function testNodeFormSaveWithoutRevision() { $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Load the node again and check the revision is different from before. - $node_revision = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node_revision = Node::load($node->id()); $this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created."); } diff --git a/core/modules/node/src/Tests/NodeSaveTest.php b/core/modules/node/src/Tests/NodeSaveTest.php index 7b0d191..2720bff 100644 --- a/core/modules/node/src/Tests/NodeSaveTest.php +++ b/core/modules/node/src/Tests/NodeSaveTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests $node->save() for saving content. * @@ -59,7 +61,7 @@ function testImport() { $node->save(); // Test the import. - $node_by_nid = node_load($test_nid); + $node_by_nid = Node::load($test_nid); $this->assertTrue($node_by_nid, 'Node load by node ID.'); $node_by_title = $this->drupalGetNodeByTitle($title); @@ -149,7 +151,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->id()); + $node = Node::load($node->id()); $this->assertEqual($node->label(), 'updated_presave', 'Static cache has been cleared.'); } diff --git a/core/modules/node/src/Tests/PageEditTest.php b/core/modules/node/src/Tests/PageEditTest.php index a014c80..af3b071 100644 --- a/core/modules/node/src/Tests/PageEditTest.php +++ b/core/modules/node/src/Tests/PageEditTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Create a node and test node edit functionality. * @@ -93,6 +95,7 @@ function testPageEdit() { * Tests changing a node's "authored by" field. */ function testPageAuthoredBy() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $this->drupalLogin($this->admin_user); // Create node to edit. @@ -116,14 +119,16 @@ function testPageAuthoredBy() { // Change the authored by field to the anonymous user (uid 0). $edit['uid[0][target_id]'] = 'Anonymous (0)'; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertIdentical($node->getOwnerId(), '0', 'Node authored by anonymous user.'); // Change the authored by field to another user's name (that is not // logged in). $edit['uid[0][target_id]'] = $this->web_user->getUsername(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertIdentical($node->getOwnerId(), $this->web_user->id(), 'Node authored by normal user.'); // Check that normal users cannot change the authored by information. diff --git a/core/modules/node/src/Tests/PageViewTest.php b/core/modules/node/src/Tests/PageViewTest.php index 0d83193..c47a97f 100644 --- a/core/modules/node/src/Tests/PageViewTest.php +++ b/core/modules/node/src/Tests/PageViewTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Create a node and test edit permissions. * @@ -19,7 +21,7 @@ class PageViewTest extends NodeTestBase { function testPageView() { // Create a node to view. $node = $this->drupalCreateNode(); - $this->assertTrue(node_load($node->id()), 'Node created.'); + $this->assertTrue(Node::load($node->id()), 'Node created.'); // Try to edit with anonymous user. $this->drupalGet("node/" . $node->id() . "/edit"); diff --git a/core/modules/node/src/Tests/SummaryLengthTest.php b/core/modules/node/src/Tests/SummaryLengthTest.php index 31ff3e3..7ac73c4 100644 --- a/core/modules/node/src/Tests/SummaryLengthTest.php +++ b/core/modules/node/src/Tests/SummaryLengthTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; + /** * Tests summary length. * @@ -23,7 +25,7 @@ public function testSummaryLength() { 'promote' => 1, ); $node = $this->drupalCreateNode($settings); - $this->assertTrue(node_load($node->id()), 'Node created.'); + $this->assertTrue(Node::load($node->id()), 'Node created.'); // Render the node as a teaser. $content = $this->drupalBuildEntityView($node, 'teaser'); diff --git a/core/modules/node/src/Tests/Views/BulkFormTest.php b/core/modules/node/src/Tests/Views/BulkFormTest.php index c2eba80..56d0d66 100644 --- a/core/modules/node/src/Tests/Views/BulkFormTest.php +++ b/core/modules/node/src/Tests/Views/BulkFormTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests\Views; +use Drupal\node\Entity\Node; + /** * Tests a node bulk form. * @@ -26,6 +28,7 @@ class BulkFormTest extends NodeTestBase { * Tests the node bulk form. */ public function testBulkForm() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $this->drupalLogin($this->drupalCreateUser(array('administer nodes'))); $node = $this->drupalCreateNode(array( 'promote' => FALSE, @@ -43,7 +46,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the status. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertFalse($node->isPublished(), 'Node has been unpublished'); // Publish action. @@ -53,7 +57,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the status. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertTrue($node->isPublished(), 'Node has been published'); // Make sticky action. @@ -66,7 +71,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the status and sticky flag. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertTrue($node->isPublished(), 'Node has been published'); $this->assertTrue($node->isSticky(), 'Node has been made sticky'); @@ -77,7 +83,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the sticky flag. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertFalse($node->isSticky(), 'Node is not sticky anymore'); // Promote to front page. @@ -90,7 +97,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the status and promoted flag. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertTrue($node->isPublished(), 'Node has been published'); $this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page'); @@ -101,7 +109,8 @@ public function testBulkForm() { ); $this->drupalPostForm(NULL, $edit, t('Apply')); // Re-load the node and check the promoted flag. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertFalse($node->isPromoted(), 'Node has been demoted'); // Delete node. @@ -112,7 +121,8 @@ public function testBulkForm() { $this->drupalPostForm(NULL, $edit, t('Apply')); $this->drupalPostForm(NULL, array(), t('Delete')); // Re-load the node and check if it has been deleted. - $node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $this->assertNull($node, 'Node has been deleted'); } diff --git a/core/modules/path/src/Tests/PathLanguageTest.php b/core/modules/path/src/Tests/PathLanguageTest.php index d6399a0..19fa8d8 100644 --- a/core/modules/path/src/Tests/PathLanguageTest.php +++ b/core/modules/path/src/Tests/PathLanguageTest.php @@ -7,6 +7,8 @@ namespace Drupal\path\Tests; +use Drupal\node\Entity\Node; + /** * Confirm that paths work with translated nodes. * @@ -69,6 +71,7 @@ protected function setUp() { * Test alias functionality through the admin interfaces. */ function testAliasTranslation() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $english_node = $this->drupalCreateNode(array('type' => 'page', 'langcode' => 'en')); $english_alias = $this->randomMachineName(); @@ -101,7 +104,8 @@ function testAliasTranslation() { $languages = $this->container->get('language_manager')->getLanguages(); // Ensure the node was created. - $english_node = node_load($english_node->id(), TRUE); + $node_storage->resetCache(array($english_node->id())); + $english_node = Node::load($english_node->id()); $french_node = $english_node->getTranslation('fr'); $this->assertTrue($english_node->hasTranslation('fr'), 'Node found in database.'); diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php index a20663d..c16630a 100644 --- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php +++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php @@ -12,6 +12,7 @@ use Drupal\quickedit\Ajax\MetadataCommand; use Drupal\Core\Ajax\AppendCommand; use Drupal\Component\Utility\Unicode; +use Drupal\node\Entity\Node; /** * Tests loading of in-place editing functionality and lazy loading of its @@ -134,7 +135,7 @@ public function testUserWithPermission() { $this->assertRaw('data-quickedit-field-id="node/1/body/en/full"'); // There should be only one revision so far. - $node = node_load(1); + $node = Node::load(1); $vids = \Drupal::entityManager()->getStorage('node')->revisionIds($node); $this->assertIdentical(1, count($vids), 'The node has only one revision.'); $original_log = $node->revision_log->value; @@ -228,7 +229,7 @@ public function testUserWithPermission() { $this->assertText('Fine thanks.'); // Ensure no new revision was created and the log message is unchanged. - $node = node_load(1); + $node = Node::load(1); $vids = \Drupal::entityManager()->getStorage('node')->revisionIds($node); $this->assertIdentical(1, count($vids), 'The node has only one revision.'); $this->assertIdentical($original_log, $node->revision_log->value, 'The revision log message is unchanged.'); @@ -277,7 +278,7 @@ public function testUserWithPermission() { $this->assertEqual($ajax_commands[0]['data'], ['entity_type' => 'node', 'entity_id' => 1], 'Updated entity type and ID returned'); // Test that a revision was created with the correct log message. - $vids = \Drupal::entityManager()->getStorage('node')->revisionIds(node_load(1)); + $vids = \Drupal::entityManager()->getStorage('node')->revisionIds(Node::load(1)); $this->assertIdentical(2, count($vids), 'The node has two revisions.'); $revision = node_revision_load($vids[0]); $this->assertIdentical($original_log, $revision->revision_log->value, 'The first revision log message is unchanged.'); @@ -392,7 +393,7 @@ public function testPseudoFields() { * editable. */ public function testDisplayOptions() { - $node = entity_load('node', '1'); + $node = Node::load('1'); $display_settings = array( 'label' => 'inline', ); diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php index abda15d..638dc9a 100644 --- a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php @@ -8,6 +8,7 @@ namespace Drupal\rdf\Tests; use Drupal\file\Tests\FileFieldTestBase; +use Drupal\node\Entity\Node; /** * Tests the RDFa markup of filefields. @@ -46,6 +47,7 @@ class FileFieldAttributesTest extends FileFieldTestBase { protected function setUp() { parent::setUp(); + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $this->fieldName = strtolower($this->randomMachineName()); $type_name = 'article'; @@ -65,7 +67,8 @@ protected function setUp() { // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name); - $this->node = node_load($nid, TRUE); + $node_storage->resetCache(array($nid)); + $this->node = Node::load($nid); $this->file = file_load($this->node->{$this->fieldName}->target_id); } diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php index 3715620..970a323 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php @@ -8,6 +8,7 @@ namespace Drupal\rdf\Tests; use Drupal\image\Tests\ImageFieldTestBase; +use Drupal\node\Entity\Node; /** * Tests the RDFa markup of imagefields. @@ -65,7 +66,7 @@ protected function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); - $this->node = node_load($nid); + $this->node = Node::load($nid); $this->file = file_load($this->node->{$this->fieldName}->target_id); } diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 44dab9b..7728dbe 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -8,6 +8,7 @@ namespace Drupal\responsive_image\Tests; use Drupal\image\Tests\ImageFieldTestBase; +use Drupal\node\Entity\Node; /** * Tests responsive image display formatter. @@ -79,12 +80,14 @@ public function testResponsiveImageFieldFormattersPrivate() { * Test responsive image formatters on node display. */ public function _testResponsiveImageFieldFormatters($scheme) { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = drupal_strtolower($this->randomMachineName()); $this->createImageField($field_name, 'article', array('uri_scheme' => $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_storage->resetCache(array($nid)); + $node = Node::load($nid); // Test that the default formatter is being used. $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); diff --git a/core/modules/rest/src/Tests/NodeTest.php b/core/modules/rest/src/Tests/NodeTest.php index 4cd2bc9..60b78b9 100644 --- a/core/modules/rest/src/Tests/NodeTest.php +++ b/core/modules/rest/src/Tests/NodeTest.php @@ -8,6 +8,7 @@ namespace Drupal\rest\Tests; use Drupal\rest\Tests\RESTTestBase; +use Drupal\node\Entity\Node; /** * Tests special cases for node entities. @@ -45,6 +46,7 @@ protected function enableNodeConfiguration($method, $operation) { * Performs various tests on nodes and their REST API. */ public function testNodes() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); $this->enableNodeConfiguration('GET', 'view'); $node = $this->entityCreate('node'); @@ -82,7 +84,8 @@ public function testNodes() { $this->assertResponse(204); // Reload the node from the DB and check if the title was correctly updated. - $updated_node = entity_load('node', $node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $updated_node = Node::load($node->id()); $this->assertEqual($updated_node->getTitle(), $new_title); // Make sure that the UUID of the node has not changed. $this->assertEqual($node->get('uuid')->getValue(), $updated_node->get('uuid')->getValue(), 'UUID was not changed.'); diff --git a/core/modules/search/src/Tests/SearchCommentTest.php b/core/modules/search/src/Tests/SearchCommentTest.php index 70d8c85..039f116 100644 --- a/core/modules/search/src/Tests/SearchCommentTest.php +++ b/core/modules/search/src/Tests/SearchCommentTest.php @@ -10,6 +10,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Component\Utility\String; use Drupal\field\Entity\FieldConfig; +use Drupal\node\Entity\Node; /** * Tests integration searching comments. @@ -59,6 +60,7 @@ protected function setUp() { * Verify that comments are rendered using proper format in search results. */ function testSearchResultsComment() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create basic_html format that escapes all HTML. $basic_html_format = entity_create('filter_format', array( 'format' => 'basic_html', @@ -105,7 +107,8 @@ function testSearchResultsComment() { 'keys' => "'" . $edit_comment['subject[0][value]'] . "'", ); $this->drupalPostForm('search/node', $edit, t('Search')); - $node2 = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node2 = Node::load($node->id()); $this->assertText($node2->label(), 'Node found in search results.'); $this->assertText($edit_comment['subject[0][value]'], 'Comment subject found in search results.'); diff --git a/core/modules/system/form.api.php b/core/modules/system/form.api.php index 3a32863..bd9141e 100644 --- a/core/modules/system/form.api.php +++ b/core/modules/system/form.api.php @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\String; +use Drupal\node\Entity\Node; /** * @addtogroup callbacks @@ -55,6 +56,8 @@ * such as how many total items were processed. */ function callback_batch_operation($MULTIPLE_PARAMS, &$context) { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; @@ -70,7 +73,8 @@ function callback_batch_operation($MULTIPLE_PARAMS, &$context) { while ($row = db_fetch_array($result)) { // Here we actually perform our processing on the current node. - $node = node_load($row['nid'], NULL, TRUE); + $node_storage->resetCache(array($row['nid'])); + $node = Node::load($row['nid']); $node->value1 = $options1; $node->value2 = $options2; node_save($node); diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 48fd3b1..66e22db 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -12,6 +12,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Language\LanguageInterface; use Drupal\block\Entity\Block; +use Drupal\node\Entity\Node; /** * Tests the invocation of hooks when creating, inserting, loading, updating or @@ -315,7 +316,7 @@ public function testNodeHooks() { )); $GLOBALS['entity_crud_hook_test'] = array(); - $node = node_load($node->id()); + $node = Node::load($node->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type node', diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ae416ed..f791d5d 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Utility\UpdateException; +use Drupal\node\Entity\Node; /** * @addtogroup hooks @@ -180,7 +181,7 @@ function hook_queue_info_alter(&$queues) { * @see \Drupal\Core\Cron::run() */ function callback_queue_worker($queue_item_data) { - $node = node_load($queue_item_data); + $node = Node::load($queue_item_data); $node->title = 'Updated title'; $node->save(); } diff --git a/core/modules/system/tests/modules/condition_test/src/FormController.php b/core/modules/system/tests/modules/condition_test/src/FormController.php index 1f13755..99f9890 100644 --- a/core/modules/system/tests/modules/condition_test/src/FormController.php +++ b/core/modules/system/tests/modules/condition_test/src/FormController.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\Core\Condition\ConditionManager; use Drupal\Core\Form\FormStateInterface; +use Drupal\node\Entity\Node; /** * Routing controller class for condition_test testing of condition forms. @@ -66,7 +67,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->condition->getConfig(); $bundles = implode(' and ', $config['bundles']); drupal_set_message(t('The bundles are @bundles', array('@bundles' => $bundles))); - $article = node_load(1); + $article = Node::load(1); $this->condition->setContextValue('node', $article); if ($this->condition->execute()) { drupal_set_message(t('Executed successfully.')); diff --git a/core/modules/taxonomy/src/Tests/TermIndexTest.php b/core/modules/taxonomy/src/Tests/TermIndexTest.php index 54d0dfb..08d6454 100644 --- a/core/modules/taxonomy/src/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/src/Tests/TermIndexTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\node\Entity\Node; /** * Tests the hook implementations that maintain the taxonomy index. @@ -101,6 +102,7 @@ protected function setUp() { * Tests that the taxonomy index is maintained properly. */ function testTaxonomyIndex() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Create terms in the vocabulary. $term_1 = $this->createTerm($this->vocabulary); $term_2 = $this->createTerm($this->vocabulary); @@ -154,7 +156,8 @@ function testTaxonomyIndex() { $this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); // Redo the above tests without interface. - $node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $node = Node::load($node->id()); $node->title = $this->randomMachineName(); // Update the article with no term changed. diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index a88b754..3074c69 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -6,7 +6,7 @@ */ use Drupal\Component\Utility\String; - +use Drupal\node\Entity\Node; /** * Page callback: Generates a page of tracked nodes for the site. @@ -46,7 +46,7 @@ function tracker_page($account = NULL) { $rows = array(); if (!empty($tracker_data)) { // Load nodes into an array with the same order as $tracker_data. - $nodes = entity_load_multiple('node', array_keys($tracker_data)); + $nodes = Node::loadMultiple(array_keys($tracker_data)); // Enrich the node data. $result = \Drupal::service('comment.statistics')->read($nodes, 'node', FALSE); diff --git a/core/modules/user/src/Tests/UserCancelTest.php b/core/modules/user/src/Tests/UserCancelTest.php index 714f8fb..506ff2a 100644 --- a/core/modules/user/src/Tests/UserCancelTest.php +++ b/core/modules/user/src/Tests/UserCancelTest.php @@ -10,6 +10,7 @@ use Drupal\simpletest\WebTestBase; use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; +use Drupal\node\Entity\Node; /** * Ensure that account cancellation methods work as expected. @@ -35,6 +36,7 @@ protected function setUp() { * Attempt to cancel account without permission. */ function testUserCancelWithoutPermission() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save(); // Create a user. @@ -58,7 +60,8 @@ function testUserCancelWithoutPermission() { $this->assertTrue($account->isActive(), 'User account was not canceled.'); // Confirm user's content has not been altered. - $test_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $test_node = Node::load($node->id()); $this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.'); } @@ -105,6 +108,7 @@ function testUserCancelUid1() { * Attempt invalid account cancellations. */ function testUserCancelInvalid() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save(); // Create a user. @@ -139,7 +143,8 @@ function testUserCancelInvalid() { $this->assertTrue($account->isActive(), 'User account was not canceled.'); // Confirm user's content has not been altered. - $test_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $test_node = Node::load($node->id()); $this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.'); } @@ -182,6 +187,7 @@ function testUserBlock() { * Disable account and unpublish all content. */ function testUserBlockUnpublish() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save(); // Create comment field on page. \Drupal::service('comment.manager')->addDefaultField('node', 'page'); @@ -229,7 +235,8 @@ function testUserBlockUnpublish() { $this->assertTrue($account->isBlocked(), 'User has been blocked.'); // Confirm user's content has been unpublished. - $test_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $test_node = Node::load($node->id()); $this->assertFalse($test_node->isPublished(), 'Node of the user has been unpublished.'); $test_node = node_revision_load($node->getRevisionId()); $this->assertFalse($test_node->isPublished(), 'Node revision of the user has been unpublished.'); @@ -247,6 +254,7 @@ function testUserBlockUnpublish() { * Delete account and anonymize all content. */ function testUserAnonymize() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save(); // Create a user. @@ -283,11 +291,13 @@ function testUserAnonymize() { $this->assertFalse(user_load($account->id(), TRUE), 'User is not found in the database.'); // Confirm that user's content has been attributed to anonymous user. - $test_node = node_load($node->id(), TRUE); + $node_storage->resetCache(array($node->id())); + $test_node = Node::load($node->id()); $this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.'); $test_node = node_revision_load($revision, TRUE); $this->assertTrue(($test_node->getRevisionAuthor()->id() == 0 && $test_node->isPublished()), 'Node revision of the user has been attributed to anonymous user.'); - $test_node = node_load($revision_node->id(), TRUE); + $node_storage->resetCache(array($revision_node->id())); + $test_node = Node::load($revision_node->id()); $this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user."); // Confirm that the confirmation message made it through to the end user. @@ -298,6 +308,7 @@ function testUserAnonymize() { * Delete account and remove all content. */ function testUserDelete() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_delete')->save(); \Drupal::moduleHandler()->install(array('comment')); $this->resetAll(); @@ -349,9 +360,11 @@ function testUserDelete() { $this->assertFalse(user_load($account->id(), TRUE), 'User is not found in the database.'); // Confirm that user's content has been deleted. - $this->assertFalse(node_load($node->id(), TRUE), 'Node of the user has been deleted.'); + $node_storage->resetCache(array($node->id())); + $this->assertFalse(Node::load($node->id()), 'Node of the user has been deleted.'); $this->assertFalse(node_revision_load($revision), 'Node revision of the user has been deleted.'); - $this->assertTrue(node_load($revision_node->id(), TRUE), "Current revision of the user's node was not deleted."); + $node_storage->resetCache(array($revision_node->id())); + $this->assertTrue(Node::load($revision_node->id()), "Current revision of the user's node was not deleted."); \Drupal::entityManager()->getStorage('comment')->resetCache(array($comment->id())); $this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.');