diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index c1ed99d..ee26631 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -206,7 +206,7 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F // Check printer friendly version. $this->drupalGet('book/export/html/' . $node->id()); $this->assertText($node->label(), 'Printer friendly title found.'); - $this->assertRaw(check_markup($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Printer friendly body found.'); + $this->assertRaw(check_markup($node->body->value, $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Printer friendly body found.'); $number++; } @@ -281,7 +281,7 @@ function testBookExport() { // Make sure each part of the book is there. foreach ($nodes as $node) { $this->assertText($node->label(), 'Node title found in printer friendly version.'); - $this->assertRaw(check_markup($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Node body found in printer friendly version.'); + $this->assertRaw(check_markup($node->body->value, $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Node body found in printer friendly version.'); } // Make sure we can't export an unsupported format. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 15c18af..c4804b8 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -516,7 +516,7 @@ function theme_comment_block($variables) { function comment_node_view(EntityInterface $node, EntityDisplay $display, $view_mode) { $links = array(); - if ($node->comment != COMMENT_NODE_HIDDEN) { + if ($node->comment->value != COMMENT_NODE_HIDDEN) { if ($view_mode == 'rss') { // Add a comments RSS element which is a URL to the comments of this node. $node->rss_elements[] = array( @@ -550,7 +550,7 @@ function comment_node_view(EntityInterface $node, EntityDisplay $display, $view_ } } } - if ($node->comment == COMMENT_NODE_OPEN) { + if ($node->comment->value == COMMENT_NODE_OPEN) { $comment_form_location = variable_get('comment_form_location_' . $node->bundle(), COMMENT_FORM_BELOW); if (user_access('post comments')) { $links['comment-add'] = array( @@ -580,7 +580,7 @@ function comment_node_view(EntityInterface $node, EntityDisplay $display, $view_ // allowed to post comments and if this node is allowing new comments. // But we don't want this link if we're building the node for search // indexing or constructing a search result excerpt. - if ($node->comment == COMMENT_NODE_OPEN) { + if ($node->comment->value == COMMENT_NODE_OPEN) { $comment_form_location = variable_get('comment_form_location_' . $node->bundle(), COMMENT_FORM_BELOW); if (user_access('post comments')) { // Show the "post comment" link if the form is on another page, or @@ -655,7 +655,7 @@ function comment_node_page_additions(EntityInterface $node) { } // Append comment form if needed. - if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->bundle(), COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) { + if (user_access('post comments') && $node->comment->value == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->bundle(), COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) { $additions['comment_form'] = comment_add($node); } @@ -874,7 +874,7 @@ function comment_view(Comment $comment, $view_mode = 'full', $langcode = NULL) { */ function comment_links(Comment $comment, EntityInterface $node) { $links = array(); - if ($node->comment == COMMENT_NODE_OPEN) { + if ($node->comment->value == COMMENT_NODE_OPEN) { if ($comment->access('delete')) { $links['comment-delete'] = array( 'title' => t('delete'), @@ -1072,7 +1072,7 @@ function comment_form_node_form_alter(&$form, $form_state) { '#weight' => 30, ); $comment_count = $node->id() ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->id()))->fetchField() : 0; - $comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment; + $comment_settings = ($node->comment->value == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment->value; $form['comment_settings']['comment'] = array( '#type' => 'radios', '#title' => t('Comments'), @@ -1113,7 +1113,7 @@ function comment_node_load($nodes, $types) { // assign values without hitting the database. foreach ($nodes as $node) { // Store whether comments are enabled for this node. - if ($node->comment != COMMENT_NODE_HIDDEN) { + if ($node->comment->value != COMMENT_NODE_HIDDEN) { $comments_enabled[] = $node->id(); } else { @@ -1142,7 +1142,7 @@ function comment_node_load($nodes, $types) { * Implements hook_node_prepare_form(). */ function comment_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) { - if (!isset($node->comment)) { + if (!isset($node->comment->value)) { $node->comment = variable_get('comment_' . $node->bundle(), COMMENT_NODE_OPEN); } } @@ -1210,7 +1210,7 @@ function comment_node_update_index(EntityInterface $node, $langcode) { if ($index_comments) { $mode = variable_get('comment_default_mode_' . $node->bundle(), COMMENT_MODE_THREADED); $comments_per_page = variable_get('comment_default_per_page_' . $node->bundle(), 50); - if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) { + if ($node->comment->value && $cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); comment_prepare_thread($comments); $build = comment_view_multiple($comments, $langcode); @@ -1236,11 +1236,11 @@ function comment_update_index() { */ function comment_node_search_result(EntityInterface $node) { // Do not make a string if comments are hidden. - if (user_access('access comments') && $node->comment != COMMENT_NODE_HIDDEN) { + if (user_access('access comments') && $node->comment->value != COMMENT_NODE_HIDDEN) { $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->id()))->fetchField(); // Do not make a string if comments are closed and there are currently // zero comments. - if ($node->comment != COMMENT_NODE_CLOSED || $comments > 0) { + if ($node->comment->value != COMMENT_NODE_CLOSED || $comments > 0) { return array('comment' => format_plural($comments, '1 comment', '@count comments')); } } diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index 221fbfc..13c2df3 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -84,7 +84,7 @@ function comment_reply(EntityInterface $node, $pid = NULL) { } // Should we show the reply box? - if ($node->comment != COMMENT_NODE_OPEN) { + if ($node->comment->value != COMMENT_NODE_OPEN) { drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); return new RedirectResponse(url('node/' . $node->id(), array('absolute' => TRUE))); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index b6a64b4..54e20e4 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -318,7 +318,7 @@ public function save(array $form, array &$form_state) { $node = node_load($form_state['values']['nid']); $comment = $this->entity; - if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { + if (user_access('post comments') && (user_access('administer comments') || $node->comment->value == COMMENT_NODE_OPEN)) { // Save the anonymous user information to a cookie for reuse. if (user_is_anonymous()) { user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index 6123825..18ae592 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -169,7 +169,7 @@ function setEnvironment(array $info) { // Change comment settings. variable_set('comment_form_location_' . $this->node->bundle(), $info['form']); variable_set('comment_anonymous_' . $this->node->bundle(), $info['contact']); - if ($this->node->comment != $info['comments']) { + if ($this->node->comment->value != $info['comments']) { $this->node->comment = $info['comments']; $this->node->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index e1e937d..4f9d70c 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -87,7 +87,7 @@ function testCommentTokenReplacement() { $tests['[comment:title]'] = $comment->subject->value; $tests['[comment:body]'] = $comment->comment_body->value; $tests['[comment:parent:title]'] = $parent_comment->subject->value; - $tests['[comment:node:title]'] = $node->title; + $tests['[comment:node:title]'] = $node->label(); $tests['[comment:author:name]'] = $this->admin_user->name; foreach ($tests as $input => $expected) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index f5f74d0..a19e1a9 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -113,7 +113,7 @@ public function testAutoCreate() { $referencing_nid = key($result); $referencing_node = node_load($referencing_nid); - $this->assertEqual($referenced_nid, $referencing_node->test_field[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], 'Newly created node is referenced from the referencing node.'); + $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. $this->drupalGet('node/' . $referencing_node->id()); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 3604142..3d73618 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -726,10 +726,10 @@ function process_entity(EntityInterface $entity) { if ($data) { // Now, overwrite the original value with our aggregated value. // This overwrites it so there is always just one entry. - $processed_entity->{$this->definition['field_name']}[$langcode] = array($base_value); + $processed_entity->getTranslation($langcode)->{$this->definition['field_name']} = array($base_value); } else { - $processed_entity->{$this->definition['field_name']}[$langcode] = array(); + $processed_entity->getTranslation($langcode)->{$this->definition['field_name']} = array(); } } @@ -740,7 +740,7 @@ function process_entity(EntityInterface $entity) { // We are supposed to show only certain deltas. if ($this->limit_values && !empty($processed_entity->{$this->definition['field_name']})) { - $all_values = !empty($processed_entity->{$this->definition['field_name']}[$langcode]) ? $processed_entity->{$this->definition['field_name']}[$langcode] : array(); + $all_values = !empty($processed_entity->getTranslation($langcode)->{$this->definition['field_name']}) ? $processed_entity->getTranslation($langcode)->{$this->definition['field_name']}->getValue() : array(); if ($this->options['delta_reversed']) { $all_values = array_reverse($all_values); } @@ -786,7 +786,7 @@ function process_entity(EntityInterface $entity) { } } } - $processed_entity->{$this->definition['field_name']}[$langcode] = $new_values; + $processed_entity->getTranslation($langcode)->{$this->definition['field_name']} = $new_values; } return $processed_entity; diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 9637826..3c4c2cd 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -210,7 +210,7 @@ function testDeleteFieldInstance() { field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('instance' => $instance)); $this->assertEqual(count($found), 10, 'Correct number of entities found after deleting'); foreach ($entities as $id => $entity) { - $this->assertEqual($this->entities[$id]->{$field->id()}->value, $entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Entity $id with deleted data loaded correctly"); + $this->assertEqual($this->entities[$id]->{$field->id()}->value, $entity->{$field->id()}->value, "Entity $id with deleted data loaded correctly"); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index 8658c52..c42950d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -107,7 +107,7 @@ public function _testSimpleFieldRender() { for ($key = 0; $key < 2; $key++) { $field = $this->fields[$key]; $rendered_field = $view->style_plugin->getField($i, $field['field_name']); - $expected_field = $this->nodes[$i]->{$field['field_name']}[Language::LANGCODE_NOT_SPECIFIED][0]['value']; + $expected_field = $this->nodes[$i]->{$field['field_name']}->value; $this->assertEqual($rendered_field, $expected_field); } } @@ -146,7 +146,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -169,7 +169,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 1, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -189,7 +189,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}->getValue(); array_splice($pure_items, 0, -3); $pure_items = array_reverse($pure_items); foreach ($pure_items as $j => $item) { @@ -210,7 +210,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $items[] = $pure_items[0]['value']; $items[] = $pure_items[4]['value']; $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.'); @@ -228,7 +228,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 87e099e..10cada8 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -60,7 +60,7 @@ function testNodeDisplay() { // Check that the default formatter is displaying with the file name. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); $default_output = theme('file_link', array('file' => $node_file)); $this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index f2c45b6..374b5fd 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -35,7 +35,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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()))); // Change the path to contain multiple subdirectories. @@ -46,7 +46,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], TRUE); + $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()))); // Check the path when used with tokens. @@ -58,7 +58,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php index d031ffe..7f051f5 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php @@ -67,7 +67,7 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index fb9f67e..c579bf8 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -47,7 +47,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node = node_load($nid, TRUE); - $node_file_r1 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); @@ -56,7 +56,7 @@ function testRevisions() { // Upload another file to the same node in a new revision. $this->replaceNodeFile($test_file, $field_name, $nid); $node = node_load($nid, TRUE); - $node_file_r2 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); @@ -64,7 +64,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $current_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $current_file = file_load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); @@ -74,7 +74,7 @@ function testRevisions() { // Check that the file is still the same as the previous revision. $this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node = node_load($nid, TRUE); - $node_file_r3 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.'); @@ -82,7 +82,7 @@ function testRevisions() { // Revert to the first revision and check that the original file is active. $this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node = node_load($nid, TRUE); - $node_file_r4 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file_r4 = file_load($node->{$field_name}->target_id); $node_vid_r4 = $node->getRevisionId(); $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.'); @@ -96,7 +96,7 @@ function testRevisions() { // Attach the second file to a user. $user = $this->drupalCreateUser(); - $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'] = $node_file_r3->id(); + $user->{$field_name}->target_id = $node_file_r3->id(); $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['display'] = 1; $user->save(); $this->drupalGet('user/' . $user->uid . '/edit'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index a7cf1e5..2b3019c 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -47,7 +47,7 @@ function testRequired() { $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); @@ -63,7 +63,7 @@ function testRequired() { // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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.'); } @@ -93,7 +93,7 @@ function testFileMaxSize() { // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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))); @@ -109,7 +109,7 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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())))); } @@ -131,7 +131,7 @@ function testFileExtension() { // Check that the file can be uploaded with no extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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.'); @@ -149,7 +149,7 @@ function testFileExtension() { // Check that the file can be uploaded with extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $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/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 4b74bfc..2e6e807 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -46,7 +46,7 @@ function testSingleValuedWidget() { // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. @@ -79,7 +79,7 @@ function testSingleValuedWidget() { // Save the node and ensure it does not have the file. $this->drupalPost(NULL, array(), t('Save and keep published')); $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']), 'File was successfully removed from the node.'); + $this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.'); } } @@ -196,7 +196,7 @@ function testMultiValuedWidget() { preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']), 'Node was successfully saved without any files.'); + $this->assertTrue(empty($node->{$field_name}->target_id), 'Node was successfully saved without any files.'); } } @@ -216,7 +216,7 @@ function testPrivateFileSetting() { $this->drupalPost("admin/structure/types/manage/$type_name/fields/$instance->id/field", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php index 1b8a82f..cfeee72 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php @@ -50,7 +50,7 @@ function testPrivateFile() { $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$field_name}->target_id); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); @@ -62,7 +62,7 @@ function testPrivateFile() { $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$no_access_field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $node_file = file_load($node->{$no_access_field_name}->target_id); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 36d323d..5036c3e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -47,7 +47,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node = node_load($nid, TRUE); - $file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $file = file_load($node->{$field_name}->target_id); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php index 75af0b0..6139abc 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php @@ -72,7 +72,7 @@ function setUp() { function testDisableFilterModule() { // Create a new node. $node = $this->drupalCreateNode(array('promote' => 1)); - $body_raw = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']; + $body_raw = $node->body->value; $format_id = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']; $this->drupalGet('node/' . $node->id()); $this->assertText($body_raw, 'Node body found.'); diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index ddc7b72..db5a710 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -529,7 +529,7 @@ function createForumTopic($forum, $container = FALSE) { // Retrieve node object, ensure that the topic was created and in the proper forum. $node = $this->drupalGetNodeByTitle($title); $this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title))); - $this->assertEqual($node->taxonomy_forums[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], $tid, 'Saved forum topic was in the expected forum'); + $this->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum'); // View forum topic. $this->drupalGet('node/' . $node->id()); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 29fcfda..6454a68 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -58,7 +58,7 @@ function _testImageFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(); + $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); $image_info = array( 'uri' => $image_uri, 'width' => 40, @@ -165,7 +165,7 @@ function testImageFieldSettings() { // style. $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), + 'uri' => file_load($node->{$field_name}->target_id)->getFileUri(), 'width' => 220, 'height' => 110, 'style_name' => 'medium', @@ -175,7 +175,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), + 'uri' => file_load($node->{$field_name}->target_id)->getFileUri(), 'alt' => $this->randomName(), 'title' => $this->randomName(), 'width' => 40, @@ -243,7 +243,7 @@ function testImageFieldDefaultImage() { $nid = $this->uploadNodeImage($images[1], $field_name, 'article'); $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), + 'uri' => file_load($node->{$field_name}->target_id)->getFileUri(), 'width' => 40, 'height' => 20, ); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index fd30c49..f0fd2ea 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -9,13 +9,13 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityFormControllerNG; use Drupal\Core\Language\Language; /** * Form controller for the node edit forms. */ -class NodeFormController extends EntityFormController { +class NodeFormController extends EntityFormControllerNG { /** * Default settings for this content/node type. @@ -42,7 +42,7 @@ protected function prepareEntity() { if ($node->isNew()) { foreach (array('status', 'promote', 'sticky') as $key) { // Multistep node forms might have filled in something already. - if (!isset($node->$key)) { + if ($node->$key->isEmpty()) { $node->$key = (int) in_array($key, $this->settings['options']); } } @@ -105,7 +105,7 @@ public function form(array $form, array &$form_state) { '#type' => 'textfield', '#title' => check_plain($node_type->title_label), '#required' => TRUE, - '#default_value' => $node->title, + '#default_value' => $node->title->value, '#maxlength' => 255, '#weight' => -5, ); @@ -155,7 +155,7 @@ public function form(array $form, array &$form_state) { '#type' => 'textarea', '#title' => t('Revision log message'), '#rows' => 4, - '#default_value' => !empty($node->log) ? $node->log : '', + '#default_value' => !empty($node->log->value) ? $node->log->value : '', '#description' => t('Briefly describe the changes you have made.'), '#states' => array( 'visible' => array( @@ -373,9 +373,13 @@ public function submit(array $form, array &$form_state) { // Save as a new revision if requested to do so. if (!empty($form_state['values']['revision'])) { $node->setNewRevision(); + // If a new revision is created, save the current user as revision author. + $node->setRevisionCreationTime(REQUEST_TIME); + global $user; + $node->setRevisionAuthorId($user->id()); } - node_submit($node); + $node->validated = TRUE; foreach (module_implements('node_submit') as $module) { $function = $module . '_node_submit'; $function($node, $form, $form_state); @@ -430,6 +434,32 @@ public function unpublish(array $form, array &$form_state) { } /** + * {@inheritdoc} + */ + public function buildEntity(array $form, array &$form_state) { + $entity = parent::buildEntity($form, $form_state); + // A user might assign the node author by entering a user name in the node + // form, which we then need to translate to a user ID. + if (!empty($form_state['values']['name'])) { + if ($account = user_load_by_name($form_state['values']['name'])) { + $entity->setAuthorId($account->id()); + } + else { + $entity->setAuthorId(0); + } + } + + if (!empty($form_state['values']['date']) && $form_state['values']['date'] instanceOf DrupalDateTime) { + $entity->setCreatedTime($form_state['values']['date']->getTimestamp()); + } + else { + $entity->setCreatedTime(REQUEST_TIME); + } + return $entity; + } + + + /** * Overrides Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index c3ccc3c..428a68b 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -26,22 +26,21 @@ public function create(array $values) { if (empty($values['created'])) { $values['created'] = REQUEST_TIME; } - return parent::create($values)->getBCEntity(); + return parent::create($values); } /** * Overrides Drupal\Core\Entity\DatabaseStorageControllerNG::attachLoad(). */ protected function attachLoad(&$queried_entities, $load_revision = FALSE) { - $nodes = $this->mapFromStorageRecords($queried_entities, $load_revision); + $queried_entities = $this->mapFromStorageRecords($queried_entities, $load_revision); // Create an array of nodes for each content type and pass this to the // object type specific callback. To preserve backward-compatibility we // pass on BC decorators to node-specific hooks, while we pass on the // regular entity objects else. $typed_nodes = array(); - foreach ($nodes as $id => $node) { - $queried_entities[$id] = $node->getBCEntity(); + foreach ($queried_entities as $id => $node) { $typed_nodes[$node->bundle()][$id] = $queried_entities[$id]; } @@ -72,31 +71,6 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) { } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::invokeHook(). - */ - protected function invokeHook($hook, EntityInterface $node) { - $node = $node->getUntranslated()->getBCEntity(); - - // Inline parent::invokeHook() to pass on BC-entities to node-specific - // hooks. - - $function = 'field_attach_' . $hook; - // @todo: field_attach_delete_revision() is named the wrong way round, - // consider renaming it. - if ($function == 'field_attach_revision_delete') { - $function = 'field_attach_delete_revision'; - } - if (!empty($this->entityInfo['fieldable']) && function_exists($function)) { - $function($node); - } - - // Invoke the hook. - module_invoke_all($this->entityType . '_' . $hook, $node); - // Invoke the respective entity-level hook. - module_invoke_all('entity_' . $hook, $node, $this->entityType); - } - - /** * {@inheritdoc} */ protected function mapToDataStorageRecord(EntityInterface $entity, $langcode) { diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php index ecc41c9..fce9466 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php @@ -103,7 +103,7 @@ public function preSaveRevision(EntityStorageControllerInterface $storage_contro // need to make sure $entity->log is reset whenever it is empty. // Therefore, this code allows us to avoid clobbering an existing log // entry with an empty one. - $record->log = $this->original->log; + $record->log = $this->original->log->value; } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php index 2ba7e94..2511dc3 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php @@ -98,7 +98,7 @@ function testRevisions() { // Confirm the correct revision text appears on "view revisions" page. $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/view"); - $this->assertText($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Correct text displays for version.'); + $this->assertText($node->body->value, 'Correct text displays for version.'); // Confirm the correct log message appears on "revisions overview" page. $this->drupalGet("node/" . $node->id() . "/revisions"); @@ -119,7 +119,7 @@ function testRevisions() { )), 'Revision reverted.'); $reverted_node = node_load($node->id(), TRUE); - $this->assertTrue(($nodes[1]->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); + $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); // Confirm that this is not the current version. $node = node_revision_load($node->getRevisionId()); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index 923ae27..f290f95 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -86,7 +86,7 @@ function testRevisions() { // Confirm the correct revision text appears on "view revisions" page. $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/view"); - $this->assertText($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Correct text displays for version.'); + $this->assertText($node->body->value, 'Correct text displays for version.'); // Confirm the correct log message appears on "revisions overview" page. $this->drupalGet("node/" . $node->id() . "/revisions"); @@ -103,7 +103,7 @@ function testRevisions() { array('@type' => 'Basic page', '%title' => $nodes[1]->label(), '%revision-date' => format_date($nodes[1]->revision_timestamp))), 'Revision reverted.'); $reverted_node = node_load($node->id(), TRUE); - $this->assertTrue(($nodes[1]->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); + $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); // Confirm that this is not the default version. $node = node_revision_load($node->getRevisionId()); @@ -136,7 +136,7 @@ function testRevisions() { // This will create a new revision that is not "front facing". $new_node_revision = clone $node; $new_body = $this->randomName(); - $new_node_revision->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $new_body; + $new_node_revision->body->value = $new_body; // Save this as a non-default revision. $new_node_revision->setNewRevision(); $new_node_revision->isDefaultRevision = FALSE; diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php index 9b4401a..f19960f 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php @@ -56,7 +56,7 @@ function testImport() { 'type' => 'article', 'nid' => $test_nid, ); - $node = node_submit(entity_create('node', $node)); + $node = entity_create('node', $node); $node->enforceIsNew(); // Verify that node_submit did not overwrite the user ID. diff --git a/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php b/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php index 4924f56..ae063f8 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php @@ -118,7 +118,7 @@ public function testRowPlugin() { foreach ($this->nodes as $node) { $body = $node->body; $teaser = $body[Language::LANGCODE_NOT_SPECIFIED][0]['summary']; - $full = $body[Language::LANGCODE_NOT_SPECIFIED][0]['value']; + $full = $body->value; $this->assertFalse(strpos($output, $teaser) !== FALSE, 'Make sure the teaser appears in the output of the view.'); $this->assertTrue(strpos($output, $full) !== FALSE, 'Make sure the full text appears in the output of the view.'); } @@ -130,7 +130,7 @@ public function testRowPlugin() { foreach ($this->nodes as $node) { $body = $node->body; $teaser = $body[Language::LANGCODE_NOT_SPECIFIED][0]['summary']; - $full = $body[Language::LANGCODE_NOT_SPECIFIED][0]['value']; + $full = $body->value; $this->assertTrue(strpos($output, $teaser) !== FALSE, 'Make sure the teaser appears in the output of the view.'); $this->assertFalse(strpos($output, $full) !== FALSE, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.'); } diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index b2cc488..7c7c250 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -611,7 +611,7 @@ function hook_node_access(\Drupal\node\NodeInterface $node, $op, $account, $lang * @ingroup node_api_hooks */ function hook_node_prepare_form(\Drupal\node\NodeInterface $node, $form_display, $operation, array &$form_state) { - if (!isset($node->comment)) { + if (!isset($node->comment->value)) { $node->comment = variable_get('comment_' . $node->bundle(), COMMENT_NODE_OPEN); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index dc4cd2c..e15678b 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -520,12 +520,7 @@ function node_type_update_nodes($old_id, $new_id) { * @see Drupal\Core\Entity\Query\EntityQueryInterface */ function node_load_multiple(array $nids = NULL, $reset = FALSE) { - $entities = entity_load_multiple('node', $nids, $reset); - // Return BC-entities. - foreach ($entities as $id => $entity) { - $entities[$id] = $entity->getBCEntity(); - } - return $entities; + return entity_load_multiple('node', $nids, $reset); } /** @@ -541,8 +536,7 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) { * A fully-populated node entity, or NULL if the node is not found. */ function node_load($nid = NULL, $reset = FALSE) { - $entity = entity_load('node', $nid, $reset); - return $entity ? $entity->getBCEntity() : NULL; + return entity_load('node', $nid, $reset); } /** @@ -559,41 +553,6 @@ function node_revision_load($vid = NULL) { } /** - * Prepares a node for saving by populating the author and creation date. - * - * @param \Drupal\Core\Entity\EntityInterface $node - * A node object. - * - * @return Drupal\node\Node - * An updated node object. - */ -function node_submit(EntityInterface $node) { - global $user; - - // A user might assign the node author by entering a user name in the node - // form, which we then need to translate to a user ID. - if (isset($node->name)) { - if ($account = user_load_by_name($node->name)) { - $node->setAuthorId($account->id()); - } - else { - $node->setAuthorId(0); - } - } - - // If a new revision is created, save the current user as revision author. - if ($node->isNewRevision()) { - $node->setRevisionAuthorId($user->id()); - $node->setRevisionCreationTime(REQUEST_TIME); - } - - $node->setCreatedTime(!empty($node->date) && $node->date instanceOf DrupalDateTime ? $node->date->getTimestamp() : REQUEST_TIME); - $node->validated = TRUE; - - return $node; -} - -/** * Deletes a node revision. * * @param $revision_id diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 510e420..e0f9f31 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -92,7 +92,7 @@ function node_add($node_type) { 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'langcode' => $langcode ? $langcode : language_default()->id, - ))->getBCEntity(); + )); drupal_set_title(t('Create @name', array('@name' => $node_type->name)), PASS_THROUGH); return Drupal::entityManager()->getForm($node); } diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index 519fc21..8500b0b 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -635,7 +635,7 @@ function node_row_node_view_preprocess_node(&$vars) { unset($vars['content']['links']); } - if (!empty($options['comments']) && user_access('access comments') && $node->comment) { + if (!empty($options['comments']) && user_access('access comments') && $node->comment->value) { $vars['content']['comments'] = comment_node_page_additions($node); } } diff --git a/core/modules/node/tests/modules/node_test/node_test.module b/core/modules/node/tests/modules/node_test/node_test.module index c9b6a32..e7880e0 100644 --- a/core/modules/node/tests/modules/node_test/node_test.module +++ b/core/modules/node/tests/modules/node_test/node_test.module @@ -139,7 +139,7 @@ function node_test_node_presave(EntityInterface $node) { // Determine changes. if (!empty($node->original) && $node->original->label() == 'test_changes') { if ($node->original->label() != $node->label()) { - $node->title .= '_presave'; + $node->title->value .= '_presave'; } } } @@ -151,7 +151,7 @@ function node_test_node_update(EntityInterface $node) { // Determine changes on update. if (!empty($node->original) && $node->original->label() == 'test_changes') { if ($node->original->label() != $node->label()) { - $node->title .= '_update'; + $node->title->value .= '_update'; } } } @@ -177,7 +177,7 @@ function node_test_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\Entity function node_test_node_insert(EntityInterface $node) { // Set the node title to the node ID and save. if ($node->label() == 'new') { - $node->title = 'Node '. $node->id(); + $node->title->value = 'Node '. $node->id(); $node->save(); } } diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 683f637..38ebaa2 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -6,8 +6,7 @@ */ use Drupal\Core\Language\Language; -use Drupal\node\NodeInterface; -use Drupal\taxonomy\Plugin\Core\Entity\Term; +use Drupal\Core\Entity\EntityInterface; /** * Implements hook_help(). @@ -181,51 +180,6 @@ function path_form_element_validate($element, &$form_state, $complete_form) { } /** - * Implements hook_node_insert(). - */ -function path_node_insert(NodeInterface $node) { - if (isset($node->path)) { - $alias = trim($node->path['alias']); - // Only save a non-empty alias. - if (!empty($alias)) { - // Ensure fields for programmatic executions. - $source = 'node/' . $node->id(); - $langcode = $node->language()->id; - Drupal::service('path.crud')->save($source, $alias, $langcode); - } - } -} - -/** - * Implements hook_node_update(). - */ -function path_node_update(NodeInterface $node) { - if (isset($node->path)) { - $path = $node->path; - $alias = trim($path['alias']); - // Delete old alias if user erased it. - if (!empty($path['pid']) && empty($path['alias'])) { - Drupal::service('path.crud')->delete(array('pid' => $path['pid'])); - } - // Only save a non-empty alias. - if (!empty($path['alias'])) { - // Ensure fields for programmatic executions. - $source = 'node/' . $node->id(); - $langcode = $node->language()->id; - Drupal::service('path.crud')->save($source, $alias, $langcode, $path['pid']); - } - } -} - -/** - * Implements hook_node_predelete(). - */ -function path_node_predelete(NodeInterface $node) { - // Delete all aliases associated with this node. - Drupal::service('path.crud')->delete(array('source' => 'node/' . $node->id())); -} - -/** * Implements hook_form_FORM_ID_alter() for taxonomy_term_form(). */ function path_form_taxonomy_term_form_alter(&$form, $form_state) { @@ -265,7 +219,7 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) { * Implements hook_entity_field_info(). */ function path_entity_field_info($entity_type) { - if ($entity_type === 'taxonomy_term') { + if ($entity_type === 'taxonomy_term' || $entity_type === 'node') { $info['definitions']['path'] = array( 'type' => 'path_field', 'label' => t('The path alias'), @@ -277,48 +231,53 @@ function path_entity_field_info($entity_type) { } /** - * Implements hook_taxonomy_term_insert(). + * Implements hook_entity_insert(). + * + * @todo: Move this to methods on the FieldItem class. */ -function path_taxonomy_term_insert(Term $term) { - if (isset($term->path)) { - $term->path->alias = trim($term->path->alias); +function path_entity_insert(EntityInterface $entity) { + if ($entity->getPropertyDefinition('path')) { + $entity->path->alias = trim($entity->path->alias); // Only save a non-empty alias. - if (!empty($term->path->alias)) { + if (!empty($entity->path->alias)) { // Ensure fields for programmatic executions. - $source = 'taxonomy/term/' . $term->id(); - $langcode = Language::LANGCODE_NOT_SPECIFIED; - Drupal::service('path.crud')->save($source, $term->path->alias, $langcode); + $uri = $entity->uri(); + $langcode = $entity->language()->id; + Drupal::service('path.crud')->save($uri['path'], $entity->path->alias, $langcode); } } } /** - * Implements hook_taxonomy_term_update(). + * Implements hook_entity_update(). */ -function path_taxonomy_term_update(Term $term) { - if (isset($term->path)) { - $term->path->alias = trim($term->path->alias); +function path_entity_update(EntityInterface $entity) { + if ($entity->getPropertyDefinition('path')) { + $entity->path->alias = trim($entity->path->alias); // Delete old alias if user erased it. - if (!empty($term->path->pid) && empty($term->path->alias)) { - Drupal::service('path.crud')->delete(array('pid' => $term->path->pid)); + if ($entity->path->pid && !$entity->path->alias) { + Drupal::service('path.crud')->delete(array('pid' => $entity->path->pid)); } // Only save a non-empty alias. - if ($term->path->alias) { - $pid = (!empty($term->path->pid) ? $term->path->pid : NULL); + if ($entity->path->alias) { + $pid = $entity->path->pid; // Ensure fields for programmatic executions. - $source = 'taxonomy/term/' . $term->id(); - $langcode = Language::LANGCODE_NOT_SPECIFIED; - Drupal::service('path.crud')->save($source, $term->path->alias, $langcode, $pid); + $uri = $entity->uri(); + $langcode = $entity->language()->id; + Drupal::service('path.crud')->save($uri['path'], $entity->path->alias, $langcode, $pid); } } } /** - * Implements hook_taxonomy_term_delete(). + * Implements hook_entity_predelete(). */ -function path_taxonomy_term_delete(Term $term) { - // Delete all aliases associated with this term. - Drupal::service('path.crud')->delete(array('source' => 'taxonomy/term/' . $term->id())); +function path_entity_predelete(EntityInterface $entity) { + if ($entity->getPropertyDefinition('path')) { + // Delete all aliases associated with this term. + $uri = $entity->uri(); + Drupal::service('path.crud')->delete(array('source' => $uri['path'])); + } } /** diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php index 8009241..cdb45bc 100644 --- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php +++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php @@ -123,7 +123,7 @@ public function _testPictureFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(); + $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); $image_info = array( 'uri' => $image_uri, 'width' => 40, diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php index 11176dc..f1a69cc 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php @@ -73,7 +73,7 @@ public function setUp() { $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name); $this->node = node_load($nid, TRUE); - $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $this->file = file_load($this->node->{$this->fieldName}->target_id); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php index a622a8c..14af8f6 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php @@ -73,7 +73,7 @@ public function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); $this->node = node_load($nid); - $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $this->file = file_load($this->node->{$this->fieldName}->target_id); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php index dd13cf9..c2340f4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -218,7 +218,7 @@ function testFieldUpgradeToConfig() { )); field_attach_load('node', array(2 => $entity), FIELD_LOAD_CURRENT, array('instance' => entity_create('field_instance', $deleted_instance))); $deleted_value = $entity->get('test_deleted_field'); - $this->assertEqual($deleted_value[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Some deleted value'); + $this->assertEqual($deleted_value->value, 'Some deleted value'); // Check that creation of a new node works as expected. $value = $this->randomName(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php index dd9bcf9..444726c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -69,7 +69,7 @@ public function testUserPictureUpgrade() { // Check the user picture and file usage record. $user = user_load(1); - $file = file_load($user->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); + $file = file_load($user->user_picture->target_id); $this->assertEqual('public://user_pictures_dir/faked_image.png', $file->getFileUri()); $usage = file_usage()->listUsage($file); $this->assertEqual(1, $usage['file']['user'][1]); diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index 5758997..498bd33 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -116,7 +116,7 @@ function testContentTranslation() { // Update original and mark translation as outdated. $node_body = $this->randomName(); - $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $node_body; + $node->body->value = $node_body; $edit = array(); $edit["body[$langcode][0][value]"] = $node_body; $edit['translation[retranslate]'] = TRUE; @@ -139,7 +139,7 @@ function testContentTranslation() { $this->drupalGet('node/add/page'); $this->assertFieldByXPath('//select[@name="langcode"]//option', Language::LANGCODE_NOT_SPECIFIED, 'Language neutral is available in language selection with disabled languages.'); $node2 = $this->createPage($this->randomName(), $this->randomName(), Language::LANGCODE_NOT_SPECIFIED); - $this->assertRaw($node2->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Language neutral content created with disabled languages available.'); + $this->assertRaw($node2->body->value, 'Language neutral content created with disabled languages available.'); // Leave just one language installed and check that the translation overview // page is still accessible. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index 2556cad..4fcbd99 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -135,6 +135,6 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->web_user->uid, TRUE); - return file_load($account->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], TRUE); + return file_load($account->user_picture->target_id, TRUE); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index 8f1c6ac..4d4633a 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -97,7 +97,7 @@ protected function setUp() { $node = $this->drupalCreateNode($values); - search_index($node->id(), 'node', $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], Language::LANGCODE_NOT_SPECIFIED); + search_index($node->id(), 'node', $node->body->value, Language::LANGCODE_NOT_SPECIFIED); $comment = array( 'uid' => $user->uid,