Commit 94cd6717 authored by catch's avatar catch

Issue #1939994 by Berdir, rlmumford: Complete conversion of nodes to the new Entity Field API.

parent f8868be9
......@@ -58,7 +58,7 @@ public function access(EntityInterface $entity, $operation, $langcode = Language
// We grant access to the entity if both of these conditions are met:
// - No modules say to deny access.
// - At least one module says to grant access.
$access = module_invoke_all($entity->entityType() . '_access', $entity->getBCEntity(), $operation, $account, $langcode);
$access = module_invoke_all($entity->entityType() . '_access', $entity, $operation, $account, $langcode);
if (($return = $this->processAccessHookResults($access)) === NULL) {
// No module had an opinion about the access, so let's the access
......
......@@ -480,9 +480,7 @@ public function getEntity() {
*/
protected function getTranslatedEntity(array $form_state) {
$langcode = $this->getFormLangcode($form_state);
$translation = $this->entity->getTranslation($langcode);
// Ensure that the entity object is a BC entity if the original one is.
return $this->entity instanceof EntityBCDecorator ? $translation->getBCEntity() : $translation;
return $this->entity->getTranslation($langcode);
}
/**
......
......@@ -327,9 +327,19 @@ function book_form_node_form_alter(&$form, &$form_state, $form_id) {
'css' => array(drupal_get_path('module', 'book') . '/css/book.admin.css'),
),
);
$form['#entity_builders'][] = 'book_node_builder';
}
}
/**
* Entity form builder to add the book information to the node.
*
* @todo: Remove this in favor of an entity field.
*/
function book_node_builder($entity_type, $entity, &$form, &$form_state) {
$entity->book = $form_state['values']['book'];
}
/**
* Form submission handler for node_form().
*
......
......@@ -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($node->body->processed, '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($node->body->processed, 'Node body found in printer friendly version.');
}
// Make sure we can't export an unsupported format.
......
......@@ -15,7 +15,7 @@
* @ingroup themeable
*/
#}
<article id="node-{{ node.nid }}" class="section-{{ depth }}">
<article id="node-{{ node.id }}" class="section-{{ depth }}">
<h1 class="book-heading">{{ title }}</h1>
{{ content }}
{{ children }}
......
......@@ -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->getType(), 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->getType(), 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->getType(), COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) {
if (user_access('post comments') && $node->comment->value == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->getType(), 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->getType(), COMMENT_NODE_OPEN);
}
}
......@@ -1209,8 +1209,8 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
if ($index_comments) {
$mode = variable_get('comment_default_mode_' . $node->getType(), COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->getType(), 50);
if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments_per_page = variable_get('comment_default_per_page_' . $node->bundle(), 50);
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'));
}
}
......
......@@ -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)));
}
......
......@@ -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'))));
......
......@@ -169,7 +169,7 @@ function setEnvironment(array $info) {
// Change comment settings.
variable_set('comment_form_location_' . $this->node->getType(), $info['form']);
variable_set('comment_anonymous_' . $this->node->getType(), $info['contact']);
if ($this->node->comment != $info['comments']) {
if ($this->node->comment->value != $info['comments']) {
$this->node->comment = $info['comments'];
$this->node->save();
}
......
......@@ -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());
......
......@@ -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;
......
......@@ -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'];
......
......@@ -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);
$file_link = array(
'#theme' => 'file_link',
'#file' => $node_file,
......
......@@ -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);
......
......@@ -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');
......
......@@ -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.');
......
......@@ -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.');
}
......
......@@ -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.
......
......@@ -82,7 +82,7 @@ function testFileListingPages() {
'files[file_' . Language::LANGCODE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($file->getFileUri()),
);
$this->drupalPost(NULL, $edit, t('Save'));
$node = entity_load('node', $node->id())->getNGEntity();
$node = entity_load('node', $node->id());
}
$this->drupalGet('admin/content/files');
......
......@@ -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.');
......
......@@ -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();
......
......@@ -72,8 +72,8 @@ function setUp() {
function testDisableFilterModule() {
// Create a new node.
$node = $this->drupalCreateNode(array('promote' => 1));
$body_raw = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'];
$format_id = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format'];
$body_raw = $node->body->value;
$format_id = $node->body->format;
$this->drupalGet('node/' . $node->id());
$this->assertText($body_raw, 'Node body found.');
......
......@@ -278,17 +278,17 @@ function forum_node_validate(EntityInterface $node, $form) {
if (_forum_node_check_node_type($node)) {
$langcode = $form['taxonomy_forums']['#language'];
// vocabulary is selected, not a "container" term.
if (!empty($node->taxonomy_forums[$langcode])) {
if (!$node->taxonomy_forums->isEmpty()) {
// Extract the node's proper topic ID.
$containers = Drupal::config('forum.settings')->get('containers');
foreach ($node->taxonomy_forums[$langcode] as $delta => $item) {
foreach ($node->taxonomy_forums as $delta => $item) {
// If no term was selected (e.g. when no terms exist yet), remove the
// item.
if (empty($item['target_id'])) {
unset($node->taxonomy_forums[$langcode][$delta]);
if (empty($item->target_id)) {
unset($node->taxonomy_forums[$delta]);
continue;
}
$term = entity_load('taxonomy_term', $item['target_id']);
$term = $item->entity;
if (!$term) {
form_set_error('taxonomy_forums', t('Select a forum.'));
continue;
......@@ -311,19 +311,18 @@ function forum_node_validate(EntityInterface $node, $form) {
* Assigns the forum taxonomy when adding a topic from within a forum.
*/
function forum_node_presave(EntityInterface $node) {
if (_forum_node_check_node_type($node)) {
// Make sure all fields are set properly:
$node->icon = !empty($node->icon) ? $node->icon : '';
reset($node->taxonomy_forums);
$langcode = key($node->taxonomy_forums);
if (!empty($node->taxonomy_forums[$langcode])) {
$node->forum_tid = $node->taxonomy_forums[$langcode][0]['target_id'];
if (!$node->taxonomy_forums->isEmpty()) {
$node->forum_tid = $node->taxonomy_forums->target_id;
// Only do a shadow copy check if this is not a new node.
if (!$node->isNew()) {
$old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->id()))->fetchField();
if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) {
// A shadow copy needs to be created. Retain new term and add old term.
$node->taxonomy_forums[$langcode][] = array('target_id' => $old_tid);
$node->taxonomy_forums[count($node->taxonomy_forums)] = array('target_id' => $old_tid);
}
}
}
......@@ -501,6 +500,7 @@ function forum_comment_delete($comment) {
* Implements hook_field_storage_pre_insert().
*/
function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields) {
$entity = $entity->getNGEntity();
if ($entity->entityType() == 'node' && $entity->isPublished() && _forum_node_check_node_type($entity)) {
$query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
foreach ($entity->getTranslationLanguages() as $langcode => $language) {
......@@ -525,6 +525,7 @@ function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields)
function forum_field_storage_pre_update(EntityInterface $entity, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array());
$entity = $entity->getNGEntity();
if ($entity->entityType() == 'node' && _forum_node_check_node_type($entity)) {
// If the node is published, update the forum index.
......@@ -1126,11 +1127,15 @@ function template_preprocess_forum_topic_list(&$variables) {
}
else {
$variables['topics'][$id]->moved = FALSE;
$variables['topics'][$id]->title = l($topic->getTitle(), 'node/' . $topic->id());
$variables['topics'][$id]->title_link = l($topic->getTitle(), 'node/' . $topic->id());
$variables['topics'][$id]->message = '';
}
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => $topic);
$variables['topics'][$id]->created = drupal_render($forum_submitted);
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array(
'uid' => $topic->getAuthorId(),
'name' => $topic->getAuthor()->getUsername(),
'created' => $topic->getCreatedTime(),
));
$variables['topics'][$id]->submitted = drupal_render($forum_submitted);
$forum_submitted = array(
'#theme' => 'forum_submitted',
'#topic' => isset($topic->last_reply) ? $topic->last_reply : NULL,
......@@ -1140,7 +1145,7 @@ function template_preprocess_forum_topic_list(&$variables) {
$variables['topics'][$id]->new_text = '';
$variables['topics'][$id]->new_url = '';
if ($topic->new_replies) {
$variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new post<span class="visually-hidden"> in topic %title</span>', '@count new posts<span class="visually-hidden"> in topic %title</span>', array('%title' => $variables['topics'][$id]->title));
$variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new post<span class="visually-hidden"> in topic %title</span>', '@count new posts<span class="visually-hidden"> in topic %title</span>', array('%title' => $variables['topics'][$id]->label()));
$variables['topics'][$id]->new_url = url('node/' . $topic->id(), array('query' => comment_new_page_count($topic->comment_count, $topic->new_replies, $topic), 'fragment' => 'new'));
}
......
......@@ -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());
......
......@@ -13,7 +13,7 @@
* - icon: The icon to display.
* - moved: A flag to indicate whether the topic has been moved to another
* forum.
* - title: The title of the topic. Safe to output.
* - title_link: The title of the topic. Safe to output.
* - message: If the topic has been moved, this contains an explanation and a
* link.
* - zebra: 'even' or 'odd', used for row class.
......@@ -21,7 +21,7 @@
* - new_replies: A flag to indicate whether there are unread comments.
* - new_url: If there are unread replies, this is a link to them.
* - new_text: Text containing the translated, properly pluralized count.
* - created: Text representing when the topic was posted. Safe to output.
* - submitted: Text representing when the topic was posted. Safe to output.
* - last_reply: Text representing when the topic was last replied to.
* - timestamp: The raw timestamp this topic was posted.
* - topic_id: Numeric ID for the current forum topic.
......@@ -42,10 +42,10 @@
{{ topic.icon }}
<div class="title">
<div>
{{ topic.title }}
{{ topic.title_link }}