function forum_node_update

Same name in other branches
  1. 7.x modules/forum/forum.module \forum_node_update()
  2. 8.9.x core/modules/forum/forum.module \forum_node_update()
  3. 10 core/modules/forum/forum.module \forum_node_update()
  4. 11.x core/modules/forum/forum.module \forum_node_update()

Implements hook_ENTITY_TYPE_update() for node entities.

File

core/modules/forum/forum.module, line 172

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);
            }
            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);
        }
        else {
            $forum_index_storage->deleteIndex($node);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.