forum_node_update

forum_node_update(EntityInterface $node)

Implements hook_ENTITY_TYPE_update() for node entities.

File

core/modules/forum/forum.module, line 171
Provides discussion forums.

Code

function forum_node_update(EntityInterface $node) {
  if (\Drupal::service('forum_manager')->checkNodeType($node)) {
    // If this is not a new revision and does exist, update the forum record,
    // otherwise insert a new one.
    /** @var \Drupal\forum\ForumIndexStorageInterface $forum_index_storage */
    $forum_index_storage = \Drupal::service('forum.index_storage');
    if ($node->getRevisionId() == $node->original->getRevisionId() && $forum_index_storage->getOriginalTermId($node)) {
      if (!empty($node->forum_tid)) {
        $forum_index_storage->update($node);
      }
      // The node is removed from the forum.
      else {
        $forum_index_storage->delete($node);
      }
    }
    else {
      if (!empty($node->forum_tid)) {
        $forum_index_storage->create($node);
      }
    }
    // If the node has a shadow forum topic, update the record for this
    // revision.
    if (!empty($node->shadow)) {
      $forum_index_storage->deleteRevision($node);
      $forum_index_storage->create($node);
    }

    // If the node is published, update the forum index.
    if ($node->isPublished()) {
      $forum_index_storage->deleteIndex($node);
      $forum_index_storage->createIndex($node);
    }
    // When a forum node is unpublished, remove it from the forum_index table.
    else {
      $forum_index_storage->deleteIndex($node);
    }
  }
}
doc_Drupal
2016-10-29 09:17:19
Comments
Leave a Comment

Please login to continue.