You are here

function forum_node_update in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/forum/forum.module \forum_node_update()
  2. 7 modules/forum/forum.module \forum_node_update()
  3. 9 core/modules/forum/forum.module \forum_node_update()

Implements hook_ENTITY_TYPE_update() for node entities.

File

core/modules/forum/forum.module, line 172
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);
      }
      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);
    }
  }
}