Commit dd95e4ba authored by Dries's avatar Dries

Issue #2049039 by Berdir: Convert node properties to methods.

parent 21226ab1
......@@ -1008,7 +1008,7 @@ function menu_item_route_access(Route $route, $href, &$map) {
* "story" content type:
* @code
* $node = menu_get_object();
* $story = $node->type == 'story';
* $story = $node->getType() == 'story';
* @endcode
*
* @param $type
......
......@@ -2534,7 +2534,7 @@ function template_preprocess_html(&$variables) {
// If on an individual node page, add the node type to body classes.
if ($node = menu_get_object()) {
$variables['attributes']['class'][] = drupal_html_class('node-type-' . $node->type);
$variables['attributes']['class'][] = drupal_html_class('node-type-' . $node->getType());
}
// Initializes attributes which are specific to the html and body elements.
......
......@@ -64,14 +64,14 @@ public function testBulkForm() {
foreach ($nodes as $node) {
$changed_node = node_load($node->id());
$this->assertTrue($changed_node->sticky, format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
$this->assertTrue($changed_node->isSticky(), format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
}
$this->assertText('Make content sticky was applied to 10 items.');
// Unpublish just one node.
$node = node_load($nodes[0]->id());
$this->assertTrue($node->status, 'The node is published.');
$this->assertTrue($node->isPublished(), 'The node is published.');
$edit = array('action_bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action');
$this->drupalPost(NULL, $edit, t('Apply'));
......@@ -80,11 +80,11 @@ public function testBulkForm() {
// Load the node again.
$node = node_load($node->id(), TRUE);
$this->assertFalse($node->status, 'A single node has been unpublished.');
$this->assertFalse($node->isPublished(), 'A single node has been unpublished.');
// The second node should still be published.
$node = node_load($nodes[1]->id(), TRUE);
$this->assertTrue($node->status, 'An unchecked node is still published.');
$this->assertTrue($node->isPublished(), 'An unchecked node is still published.');
// Set up to include just the sticky actions.
$view = views_get_view('test_bulk_form');
......
......@@ -120,13 +120,13 @@ function book_permission() {
* @param $view_mode
* The view mode of the node.
*/
function book_node_view_link(EntityInterface $node, $view_mode) {
function book_node_view_link(NodeInterface $node, $view_mode) {
$links = array();
if (isset($node->book['depth'])) {
if ($view_mode == 'full' && node_is_page($node)) {
$child_type = Drupal::config('book.settings')->get('child_type');
if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) {
if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->isPublished() && $node->book['depth'] < MENU_MAX_DEPTH) {
$links['book_add_child'] = array(
'title' => t('Add child page'),
'href' => 'node/add/' . $child_type,
......@@ -307,7 +307,7 @@ function book_form_node_form_alter(&$form, &$form_state, $form_id) {
$node = $form_state['controller']->getEntity();
$access = user_access('administer book outlines');
if (!$access) {
if (user_access('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->type))) {
if (user_access('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->getType()))) {
// Already in the book hierarchy, or this node type is allowed.
$access = TRUE;
}
......
......@@ -432,8 +432,8 @@ function comment_get_recent($number = 10) {
* "page=X" if the page number is greater than zero; empty string otherwise.
*/
function comment_new_page_count($num_comments, $new_replies, EntityInterface $node) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$mode = variable_get('comment_default_mode_' . $node->getType(), COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->getType(), 50);
$pagenum = NULL;
$flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
if ($num_comments <= $comments_per_page) {
......@@ -551,7 +551,7 @@ function comment_node_view(EntityInterface $node, EntityDisplay $display, $view_
}
}
if ($node->comment == COMMENT_NODE_OPEN) {
$comment_form_location = variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW);
$comment_form_location = variable_get('comment_form_location_' . $node->getType(), COMMENT_FORM_BELOW);
if (user_access('post comments')) {
$links['comment-add'] = array(
'title' => t('Add new comment'),
......@@ -581,7 +581,7 @@ function comment_node_view(EntityInterface $node, EntityDisplay $display, $view_
// 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) {
$comment_form_location = variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW);
$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
// if there are existing comments that the link will skip past.
......@@ -643,8 +643,8 @@ function comment_node_page_additions(EntityInterface $node) {
// Unpublished comments are not included in $node->comment_count, so show
// comments unconditionally if the user is an administrator.
if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$mode = variable_get('comment_default_mode_' . $node->getType(), COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->getType(), 50);
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments = comment_load_multiple($cids);
comment_prepare_thread($comments);
......@@ -655,13 +655,13 @@ 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->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) {
if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->getType(), COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) {
$additions['comment_form'] = comment_add($node);
}
if ($additions) {
$additions += array(
'#theme' => 'comment_wrapper__node_' . $node->type,
'#theme' => 'comment_wrapper__node_' . $node->getType(),
'#node' => $node,
'comments' => array(),
'comment_form' => array(),
......@@ -684,7 +684,7 @@ function comment_node_page_additions(EntityInterface $node) {
* The renderable array for the comment addition form.
*/
function comment_add(EntityInterface $node, $pid = NULL) {
$values = array('nid' => $node->id(), 'pid' => $pid, 'node_type' => 'comment_node_' . $node->type);
$values = array('nid' => $node->id(), 'pid' => $pid, 'node_type' => 'comment_node_' . $node->getType());
$comment = entity_create('comment', $values);
return Drupal::entityManager()->getForm($comment);
}
......@@ -1118,9 +1118,9 @@ function comment_node_load($nodes, $types) {
}
else {
$node->cid = 0;
$node->last_comment_timestamp = $node->created;
$node->last_comment_timestamp = $node->getCreatedTime();
$node->last_comment_name = '';
$node->last_comment_uid = $node->uid;
$node->last_comment_uid = $node->getAuthorId();
$node->comment_count = 0;
}
}
......@@ -1143,7 +1143,7 @@ function comment_node_load($nodes, $types) {
*/
function comment_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) {
if (!isset($node->comment)) {
$node->comment = variable_get("comment_$node->type", COMMENT_NODE_OPEN);
$node->comment = variable_get('comment_' . $node->getType(), COMMENT_NODE_OPEN);
}
}
......@@ -1158,9 +1158,9 @@ function comment_node_insert(EntityInterface $node) {
->fields(array(
'nid' => $node->id(),
'cid' => 0,
'last_comment_timestamp' => $node->changed,
'last_comment_timestamp' => $node->getChangedTime(),
'last_comment_name' => NULL,
'last_comment_uid' => $node->uid,
'last_comment_uid' => $node->getAuthorId(),
'comment_count' => 0,
))
->execute();
......@@ -1208,8 +1208,8 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
}
if ($index_comments) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$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 = comment_load_multiple($cids);
comment_prepare_thread($comments);
......@@ -1610,7 +1610,7 @@ function template_preprocess_comment(&$variables) {
$variables['attributes']['class'][] = 'by-anonymous';
}
else {
if ($comment->uid->target_id == $variables['node']->uid) {
if ($comment->uid->target_id == $variables['node']->getAuthorId()) {
$variables['attributes']['class'][] = 'by-node-author';
}
if ($comment->uid->target_id == $variables['user']->id()) {
......@@ -1651,7 +1651,7 @@ function theme_comment_post_forbidden($variables) {
if ($authenticated_post_comments) {
// We cannot use drupal_get_destination() because these links
// sometimes appear on /node and taxonomy listing pages.
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
if (variable_get('comment_form_location_' . $node->getType(), COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
$destination = array('destination' => 'comment/reply/' . $node->id() . '#comment-form');
}
else {
......@@ -1683,7 +1683,7 @@ function theme_comment_post_forbidden($variables) {
function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information.
$variables['node'] = $variables['content']['#node'];
$variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
$variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->getType(), COMMENT_MODE_THREADED);
// The comment form is optional and may not exist.
$variables['content'] += array('comment_form' => array());
......
......@@ -26,9 +26,9 @@ public function form(array $form, array &$form_state) {
// Use #comment-form as unique jump target, regardless of node type.
$form['#id'] = drupal_html_id('comment_form');
$form['#theme'] = array('comment_form__node_' . $node->type, 'comment_form');
$form['#theme'] = array('comment_form__node_' . $node->getType(), 'comment_form');
$anonymous_contact = variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT);
$anonymous_contact = variable_get('comment_anonymous_' . $node->getType(), COMMENT_ANONYMOUS_MAYNOT_CONTACT);
$is_admin = $comment->id() && user_access('administer comments');
if (!$user->isAuthenticated() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
......@@ -145,7 +145,7 @@ public function form(array $form, array &$form_state) {
'#title' => t('Subject'),
'#maxlength' => 64,
'#default_value' => $comment->subject->value,
'#access' => variable_get('comment_subject_field_' . $node->type, 1) == 1,
'#access' => variable_get('comment_subject_field_' . $node->getType(), 1) == 1,
);
// Used for conditional validation of author fields.
......@@ -178,7 +178,7 @@ protected function actions(array $form, array &$form_state) {
$element = parent::actions($form, $form_state);
$comment = $this->entity;
$node = $comment->nid->entity;
$preview_mode = variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL);
$preview_mode = variable_get('comment_preview_' . $node->getType(), DRUPAL_OPTIONAL);
// No delete action on the comment form.
unset($element['delete']);
......@@ -341,7 +341,7 @@ public function save(array $form, array &$form_state) {
}
$query = array();
// Find the current display page for this comment.
$page = comment_get_display_page($comment->id(), $node->type);
$page = comment_get_display_page($comment->id(), $node->getType());
if ($page > 0) {
$query['page'] = $page;
}
......
......@@ -121,7 +121,7 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
throw new AccessDeniedHttpException();
}
// Find the current display page for this comment.
$page = comment_get_display_page($comment->id(), $node->type);
$page = comment_get_display_page($comment->id(), $node->getType());
// @todo: Cleaner sub request handling.
$redirect_request = Request::create('/node/' . $node->id(), 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$redirect_request->query->set('page', $page);
......
......@@ -217,7 +217,7 @@ public function id() {
public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) {
if (empty($values['node_type']) && !empty($values['nid'])) {
$node = node_load(is_object($values['nid']) ? $values['nid']->value : $values['nid']);
$values['node_type'] = 'comment_node_' . $node->type;
$values['node_type'] = 'comment_node_' . $node->getType();
}
}
......
......@@ -143,7 +143,7 @@ function setEnvironment(array $info) {
$comment = entity_create('comment', array(
'cid' => NULL,
'nid' => $this->node->id(),
'node_type' => $this->node->type,
'node_type' => $this->node->getType(),
'pid' => 0,
'uid' => 0,
'status' => COMMENT_PUBLISHED,
......@@ -167,8 +167,8 @@ function setEnvironment(array $info) {
}
// Change comment settings.
variable_set('comment_form_location_' . $this->node->type, $info['form']);
variable_set('comment_anonymous_' . $this->node->type, $info['contact']);
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']) {
$this->node->comment = $info['comments'];
$this->node->save();
......
......@@ -49,7 +49,7 @@ public function testCommentNewCommentsIndicator() {
$comment = entity_create('comment', array(
'cid' => NULL,
'nid' => $this->node->id(),
'node_type' => $this->node->type,
'node_type' => $this->node->getType(),
'pid' => 0,
'uid' => $this->loggedInUser->id(),
'status' => COMMENT_PUBLISHED,
......
......@@ -49,7 +49,7 @@ function testCommentNodeCommentStatistics() {
// Checks the initial values of node comment statistics with no comment.
$node = node_load($this->node->id());
$this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.');
$this->assertEqual($node->last_comment_timestamp, $this->node->getCreatedTime(), 'The initial value of node last_comment_timestamp is the node created date.');
$this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
$this->assertEqual($node->last_comment_uid, $this->web_user->id(), 'The initial value of node last_comment_uid is the node uid.');
$this->assertEqual($node->comment_count, 0, 'The initial value of node comment_count is zero.');
......
......@@ -67,7 +67,7 @@ function testCommentTokenReplacement() {
$tests['[comment:parent:cid]'] = $comment->pid->target_id;
$tests['[comment:parent:title]'] = check_plain($parent_comment->subject->value);
$tests['[comment:node:nid]'] = $comment->nid->target_id;
$tests['[comment:node:title]'] = check_plain($node->title);
$tests['[comment:node:title]'] = check_plain($node->getTitle());
$tests['[comment:author:uid]'] = $comment->uid->target_id;
$tests['[comment:author:name]'] = check_plain($this->admin_user->getUsername());
......@@ -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->getTitle();
$tests['[comment:author:name]'] = $this->admin_user->getUsername();
foreach ($tests as $input => $expected) {
......
......@@ -77,7 +77,7 @@ protected function createEntity($values, $langcode, $node_bundle = NULL) {
}
$node = $this->drupalCreateNode(array('type' => $node_bundle));
$values['nid'] = $node->id();
$values['uid'] = $node->uid;
$values['uid'] = $node->getAuthorId();
return parent::createEntity($values, $langcode);
}
......
......@@ -41,7 +41,7 @@ function setUp() {
$this->drupalLogin($this->account);
$this->node_user_posted = $this->drupalCreateNode();
$this->node_user_commented = $this->drupalCreateNode(array('uid' => $this->account2->uid));
$this->node_user_commented = $this->drupalCreateNode(array('uid' => $this->account2->id()));
$comment = array(
'uid' => $this->loggedInUser->id(),
......
......@@ -77,7 +77,7 @@ public function setUp() {
// Create some comments and attach them to the created node.
for ($i = 0; $i < $this->masterDisplayResults; $i++) {
$comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->type));
$comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->getType()));
$comment->uid->target_id = 0;
$comment->nid->target_id = $this->node->id();
$comment->subject->value = 'Test comment ' . $i;
......
......@@ -1049,5 +1049,5 @@ function datetime_form_node_form_alter(&$form, &$form_state, $form_id) {
*/
function datetime_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) {
// Prepare the 'Authored on' date to use datetime.
$node->date = DrupalDateTime::createFromTimestamp($node->created);
$node->date = DrupalDateTime::createFromTimestamp($node->getCreatedTime());
}
......@@ -36,7 +36,7 @@ public function testSelectionHandler() {
$nodes = array();
foreach (array($node1, $node2, $node3) as $node) {
$nodes[$node->type][$node->id()] = $node->label();
$nodes[$node->getType()][$node->id()] = $node->label();
}
// Create a field and instance.
......
......@@ -48,7 +48,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_vid_r1 = $node->vid;
$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.');
$this->assertFileIsPermanent($node_file_r1, 'File is permanent.');
......@@ -57,7 +57,7 @@ function testRevisions() {
$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_vid_r2 = $node->vid;
$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.');
$this->assertFileIsPermanent($node_file_r2, 'Replacement file is permanent.');
......@@ -75,7 +75,7 @@ function testRevisions() {
$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_vid_r3 = $node->vid;
$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.');
......@@ -83,7 +83,7 @@ function testRevisions() {
$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_vid_r4 = $node->vid;
$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.');
......
......@@ -155,7 +155,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE,
$node->setNewRevision();
$node->save();
$node = node_load($nid, TRUE);
$this->assertNotEqual($nid, $node->vid, 'Node revision exists.');
$this->assertNotEqual($nid, $node->getRevisionId(), 'Node revision exists.');
}
// Attach a file to the node.
......
......@@ -75,14 +75,14 @@ function testFileListingPages() {
}
foreach ($nodes as &$node) {
$this->drupalGet('node/' . $node->nid . '/edit');
$this->drupalGet('node/' . $node->id() . '/edit');
$file = $this->getTestFile('image');
$edit = array(
'files[file_' . Language::LANGCODE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($file->getFileUri()),
);
$this->drupalPost(NULL, $edit, t('Save'));
$node = entity_load('node', $node->nid)->getNGEntity();
$node = entity_load('node', $node->id())->getNGEntity();
}
$this->drupalGet('admin/content/files');
......
......@@ -6,7 +6,7 @@
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\Plugin\Core\Entity\Term;
/**
......@@ -264,7 +264,7 @@ function forum_uri($forum) {
*/
function _forum_node_check_node_type(EntityInterface $node) {
// Fetch information about the forum field.
$instance = field_info_instance('node', 'taxonomy_forums', $node->type);
$instance = field_info_instance('node', 'taxonomy_forums', $node->getType());
return !empty($instance);
}
......@@ -341,7 +341,7 @@ function forum_node_update(EntityInterface $node) {
if (!empty($node->forum_tid)) {
db_update('forum')
->fields(array('tid' => $node->forum_tid))
->condition('vid', $node->vid)
->condition('vid', $node->getRevisionId())
->execute();
}
// The node is removed from the forum.
......@@ -356,7 +356,7 @@ function forum_node_update(EntityInterface $node) {
db_insert('forum')
->fields(array(
'tid' => $node->forum_tid,
'vid' => $node->vid,
'vid' => $node->getRevisionId(),
'nid' => $node->id(),
))
->execute();
......@@ -367,12 +367,12 @@ function forum_node_update(EntityInterface $node) {
if (!empty($node->shadow)) {
db_delete('forum')
->condition('nid', $node->id())
->condition('vid', $node->vid)
->condition('vid', $node->getRevisionId())
->execute();
db_insert('forum')
->fields(array(
'nid' => $node->id(),
'vid' => $node->vid,
'vid' => $node->getRevisionId(),
'tid' => $node->forum_tid,
))
->execute();
......@@ -389,7 +389,7 @@ function forum_node_insert(EntityInterface $node) {
$nid = db_insert('forum')
->fields(array(
'tid' => $node->forum_tid,
'vid' => $node->vid,
'vid' => $node->getRevisionId(),
'nid' => $node->id(),
))
->execute();
......@@ -418,7 +418,7 @@ function forum_node_load($nodes) {
$node_vids = array();
foreach ($nodes as $node) {
if (_forum_node_check_node_type($node)) {
$node_vids[] = $node->vid;
$node_vids[] = $node->getRevisionId();
}
}
if (!empty($node_vids)) {
......@@ -501,18 +501,18 @@ function forum_comment_delete($comment) {
* Implements hook_field_storage_pre_insert().
*/
function forum_field_storage_pre_insert(EntityInterface $entity, &$skip_fields) {
if ($entity->entityType() == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
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) {
$translation = $entity->getTranslation($langcode);
$query->values(array(
'nid' => $entity->id(),
'title' => $translation->title->value,
'title' => $translation->label(),
'tid' => $translation->taxonomy_forums->target_id,
'sticky' => $entity->sticky,
'created' => $entity->created,
'sticky' => (int) $entity->isSticky(),
'created' => $entity->getCreatedTime(),
'comment_count' => 0,
'last_comment_timestamp' => $entity->created,
'last_comment_timestamp' => $entity->getCreatedTime(),
));
}
$query->execute();
......@@ -528,26 +528,27 @@ function forum_field_storage_pre_update(EntityInterface $entity, &$skip_fields)
if ($entity->entityType() == 'node' && _forum_node_check_node_type($entity)) {
// If the node is published, update the forum index.
if ($entity->status) {
if ($entity->isPublished()) {
// We don't maintain data for old revisions, so clear all previous values
// from the table. Since this hook runs once per field, per object, make
// sure we only wipe values once.
if (!isset($first_call[$entity->nid])) {
$first_call[$entity->nid] = FALSE;
if (!isset($first_call[$entity->id()])) {
$first_call[$entity->id()] = FALSE;
db_delete('forum_index')->condition('nid', $entity->id())->execute();
}
$query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
foreach ($entity->taxonomy_forums as $language) {
foreach ($language as $item) {
foreach ($entity->getTranslationLanguages() as $langcode => $language) {
$translation = $entity->getTranslation($langcode);
foreach ($translation->taxonomy_forums as $item) {
$query->values(array(
'nid' => $entity->nid,
'title' => $entity->title,
'tid' => $item['target_id'],
'sticky' => $entity->sticky,
'created' => $entity->created,
'nid' => $entity->id(),
'title' => $translation->label(),
'tid' => $item->target_id,
'sticky' => (int) $entity->isSticky(),
'created' => $entity->getCreatedTime(),
'comment_count' => 0,
'last_comment_timestamp' => $entity->created,
'last_comment_timestamp' => $entity->getCreatedTime(),
));
}
}
......@@ -1109,7 +1110,7 @@ function template_preprocess_forum_topic_list(&$variables) {
'#new_posts' => $topic->new,
'#num_posts' => $topic->comment_count,
'#comment_mode' => $topic->comment_mode,
'#sticky' => $topic->sticky,
'#sticky' => $topic->isSticky(),
'#first_new' => $topic->first_new,
);